0

I am trying to write a visio application. If I write in Macro (within visio app), I get all objects. However, when I try to write same code in Visual Studio 2019, I cant find references. Like ActiveWindow or visSectionAction. I am trying to follow this: Add Menu Action Programatically to Visio

What references am I missing. I added nuget package, added office object library. TIA

braX
  • 11,506
  • 5
  • 20
  • 33
genericuser
  • 1,430
  • 4
  • 22
  • 40

1 Answers1

0

To use Visio object model from a .NET application, you need to add a reference to Visio type library to that application. This is Microsoft.Office.Interop.Visio. You could start over in the Microsoft documentation: https://learn.microsoft.com/en-us/visualstudio/vsto/visio-object-model-overview

The global VBA objects, like ActiveWindow, are available as app.ActiveWindow (assuming the "app" is the root Visio Application object you access). In case of an Add-In:

var w = Globals.ThisAddIn.Application.ActiveWindow

or in case you need to access from a method of the add-in:

var w = Application.ActiveWindow

Enumerations should be prefixed with its type: VisSectionIndices.visSectionAction.

Please note that the answer in the linked question explains how to add a menu item to a shape, not to the application. If you want to extend application menu rather than shape menu (?), you need to add your menu item to the ribbon definition.

Nikolay
  • 10,752
  • 2
  • 23
  • 51