Start a macro by a toolbar-button

K

Klaus

Hi!

I'd like to start a Visio macro by a button in a custom
toolbar. I already studied visio help and the knowledge
base in detail, but I find no way to manage this. Is this
feasible. If yes, how?

Thanks in advance!

Klaus
 
V

Vidush

Hi
you can use the UIObject to add a costum toolbar to your drawing document(reccomended, this way the toolbar appears only when the appropriate drawing document is active) or to the application (Open/Activate an other drawing document and the costum toolbar is still there) .

here is some of my work, if you want to test it yourself make shure that the active document is the document that has the macro,
my macro name is "Compile" and its located in ShowInMenu Module,

Public Sub AddToolbar()

Dim vsoUIObject As Visio.UIObject
Dim vsoToolbarSet As Visio.ToolbarSet
Dim vsoToolbarItems As Visio.ToolbarItems
Dim vsoToolbarItem As Visio.ToolbarItem
Dim vsoToolbar As Visio.Toolbar
Dim DrawingDoc As Document

Set DrawingDoc = ActiveDocument

If Not DrawingDoc.CustomToolbars Is Nothing Then
Exit Sub
End If

'Get the UIObject object
Set vsoUIObject = Application.BuiltInToolbars(0)

'Get the drawing window toolbar sets.
Set vsoToolbarSet = vsoUIObject.ToolbarSets.ItemAtID(visUIObjSetDrawing)

'Get the new Toolbar from Toolbars colection
Set vsoToolbar = vsoToolbarSet.Toolbars.Add
vsoToolbar.Caption = "MyToolBar"
vsoToolbar.Position = visBarTop

Set vsoToolbarItems = vsoToolbar.ToolbarItems

'Add a new button
Set vsoToolbarItem = vsoToolbarItems.Add
vsoToolbarItem.CntrlType = visCtrlTypeBUTTON

Dim PicturePath As String
PicturePath = "C:\...\Picture\"

'Set the properties for the new menu item
vsoToolbarItem.Caption = "Compile"
vsoToolbarItem.AddOnName = "ShowInMenu.Compile"
vsoToolbarItem.IconFileName PicturePath & "compile.ico"

' Add the toolBar to the active document
DrawingDoc.SetCustomToolbars vsoUIObject

' Add the toolBar to the application
' Application.SetCustomToolbars vsoUIObject

End Sub

if an other document has the macro (One of your stencils for exmple), the other document must be in the references list of the toolbar Document, And AddOnName property should be - OtherDocumentName.ModuleThatHasTheMacro.MacroName

Good luck!, Vidush.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top