VSTO Sample code For Sensitivity label Ribbon Item OnClick Events in C# - vsto

I need to get changes to a sensitivity label done by clicking the Ribbon item in Microsoft Word.
Does anyone have sample code on catching event changes for sensitivity labels in particular for VSTO C#?
We are using ribbon XML and not ribbon designer and extending AddInBase to start up the word application.
I have tried Document events. I have tried Commands.
Any help will be greatly appreciated. I can't find much documentation for VSTO

These are some VBA references.
You can try using the Document.SensitivityLabel property on ThisDocument/ActiveDocument and listen to the SensitivityLabel.LabelChanged event

The answer is a mixture of #cs answer and #Dimitry's answer (I don't have enough reputation points to mark that your comment was very useful). So thank you very much both of you for your assistance
VSTO no longer has support, so visual studio office tools include interop dll v15.0.0 for .net framework version 4.7.2. On our development machine, we have office 365, which from what I read means the latest interop dll will be installed as part of the installation process which has Microsoft word object library v 16.0
Adding Lastest interop to Visual Studio as a com reference
However visual studio still did not update the interop interfaces. What I had to do was change the wrapper property in the csproject from
<WrapperTool>primary</WrapperTool> to <WrapperTool>tlbimp</WrapperTool>
This updated the interfaces and allowed me to get access to the Document.SensitivityLabel object.
So thank you to all that commented it was greatly appreciated.

Related

Reporting template in Visual Studio 2017

The Reporting template seems missing in VS2017 (I am using Visual Basic). Any way to get it back?
I have already tried installing SQL Server Data tools and the rdlc extension from the marketplace, but it still doesn't show up.
The template is available in the Add New Item window. Select Visual C# and then look for the Report and Report Wizard templates. These templates are only visible under Visual C#, not under any subitem.
Try updating ReportViewer to version 14.0.0.0 and installing Microsoft.RdlcDesigner. This worked for me for Visual C# and then just like J.Bunch said there is no sub item Reporting like there was before so you just scroll down thorough all items. Also try this although the example is for C# I think it should at least help you with VB.Net as well. Hope it helps.

{System.__ComObject} properties in Visual Studio debugger not the same as Excel VB

I've been trying everything for a week and I cannot find a soltion for this. The problem is that I have been automating process in CATIA with Excel VB and now I want to use Visual Studio 2015. The only problem that I have is the debugger in Visual Studio. When I use:
Dim CATIA As INFITF.Application = GetObject(, "CATIA.Application");
I have a {System.__ComObject} as a result, clicking on "Dynamic View" (Debugger/Locals) I dont get any propertie of the object. If instead of CATIA.Application, Excel.Application is used I can see in the "Dynamic View" the different properties of the object.
http://stpserver.webcindario.com/vstudiodebugger.png
Also when I type the code:
Set CATIA = GetObject(,"CATIA.Application")
In Excel VBA, in the debugger it will appear all the properties of the object.
http://stpserver.webcindario.com/excevbadebugger.png
My question is how I can see in the Visual Studio 2015 debugger window the properties of the CATIA object as I can see them in Excel VB debugger.
PD: I have imported all the necessary references in Visual Studio 2015
Related post: Use C# for Catia V5 Automation
Sadly I do not know the exact VB.net code you will need but this should point you in the right direction. Since you want the COM object the process is the same, only the syntax is different.
In your Visual Studio project right click and Add Reference. Under the COM tab, Type Libraries section look for: CATIA V5 InfInterfaces Object Library. This is needed for INFITF.Application. If you want to work with other objects in Catia you will need MecModInterfaces, PartInterfaces, ProductInterfaces, and for HybridShape types you will need the CATGSMIDLItf Object Library (This has a different name prior to R23 but I do not remember what it was).
After that you need to use Marshal to attach to the Catia process.
The version of Visual Studio should not matter since you are using COM. It does matter if you are using CAA-RADE which has version specific tools.
I have successfully used Visual Studio 2010 (with Catia R19-20), VS2012 (with Catia R22 and R23), VS2013 and VS2015 (with Catia R23).
I think your problem might be with the missing references.
Latest version supported by Dassault Systemes for their CATIA (by the way, which version? what OS?) is VS2013 (hope I'm not doing a mistake).

Is it possible to write Excel VBA Code in Visual Studio

Is there a way to write VBA Code in Visual Studio. If not is there any other alternatives?
The best you can do is bend the office Visual Basic Editor (VBE) tool to your liking. If you stay in it's native environment you get the full power of error detection, Intellisense, live code running, etc.
My tips...
In the VBE go to Tools > Options > Editor tab.
Turn off 'Auto Syntax Check'. You still get code highlighted errors but no annoying popups.
Go to the Editor Format tab and change the Font to Consolas (Western), Size 11.
For code indenting install the awesome, free, Code Manager. It adds some sick keyboard shortcuts.
Make the Edit toolbar easily accessible for code commenting/uncommenting.
Use Rubberduck to add unit testing, source control, code inspections and refactoring functionality.
With those simple changes you end up with a half way decent, useful, and keyboard friendly environment to write your visually appealing code. :-D
VBA code for Excel can only be written inside Excel using the VBA IDE. VBA projects are stored as part of the Excel file and cannot be loaded into Visual Studio.
However, you can write VSTO (Visual Studio Tools for Office) managed add-ins for Excel using Visual Studio. The following MSDN page covers both developing with VBA and VSTO.
Excel for developers
You could also use the interop features of VBA to consume a (COM) object written in Visual Studio from your VBA code.
I've been looking for an answer to this question myself.
Best I've found myself is the option of exporting a Module ect from Excel with the code you've already written (or blank) and load that up in the Visual Studio Environment.
It doesn't offer much, but the highlighted text and auto indenting is nice and makes it much easier to read compared to the standard VBA environment.
Then once you're done just import it back into Excel.
There is a VSCode extension to do this.
It allows you to write code in VSCode and export it to Excel.
This extension is very useful when you develop in VBA.
Here's the link to download the XVBA extension
Edit :
As Peter Macej said in comment, this solution only works for Visual Studio Code not for Visual Studio
You can certainly add and edit a VBA file (.vb) in your Visual Studio solution, but the intellisense will be worthless/screwed up.
This extension for VScode would probably provide a much better experience: https://marketplace.visualstudio.com/items?itemName=spences10.VBA
If your goal is have your VBA code exposed to source control so you can track changes, then it's still worth it to include in your Visual Studio solution, but just store that VBA code in a plain text file and then use the Excel interop to load it into the appropriate module within the excel workbook, e.g.:
xlWorkbook.VBProject.VBComponents["ThisWorkbook"].CodeModule.AddFromFile(#"C:\PathToYour\VBAcode.txt");
And there are other methods to delete/replace code lines, etc....
You can try xlWings package for python and use it with VS Code https://youtu.be/xoO-Fx0fTpM

Visual Studio Macros Editor

Is there a way to change the macro editor from this default one:
It feels like such a downgrade from Visual Studio 2010. Can I configure Office to use that instead?
no there is no way to my knowledge, VS.NET does not support VBA.
what you can do if you are creating a new word or excel file is create a managed office solution, having installed the VSTO 2010 (Visual Studio Tools for Office) you are able to create managed documents which are handled inside VS 2010 and the automation language is not VBA anymore but C# or VB.NET instead.
this is a viable solution for new files, for legacy files either you convert them if they are small or you keep old VBA code and old VBA editor as in your picture.
Mark I wish MS made a tool to convert from the old format to the new one! :(
There are things you can do to improve it:
Tools > Options > Editor :
Uncheck "Auto Syntax Check"
Tools > Options > Edit Format:
Customize the colors and font
Install the VBA Rubberduck:
http://rubberduckvba.com/
The RubberDuck does auto-indent for you. It also helps you with "unit testing, source control, from code inspections, and refactorings"

Microsoft Chart Controls in Visual Studio 2010?

Is this possible? I installed them, but they don't appear. Do I have to import them or something?
If you cannot see the Chart control in the Toolbox, right click in the Toolbox, select Choose Items, and then select the following namespaces in the .NET Framekwork Components tab:
System.Web.UI.DataVisualization.Charting
System.Windows.Forms.DataVisualization.Charting
Please, take a look: How use MS chart control with VS 2010?
I haven't tried it with VS2010, but I would assume the process for using it is exactly the same as described there for other versions of VS. It won't appear in the tool box until you instal the add-ons
According to this blog post from January 2010:
The Microsoft Chart Control is available as separate installation for .NET Framework 3.5 and will be included in .NET Framework 4.0.
It could be that the controls haven't been updated to work with VS2010 because of this. If they're not in the Beta 2 by default (I don't have it installed on this machine to check) then it might be that they're only going to be included in the full release.
The Chart controls are included in version 4. Here's where you can find the types:
ASP.NET:
http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.aspx
Winforms:
http://msdn.microsoft.com/en-us/library/dd489065%28v=VS.100%29.aspx