Add Visio Menu Bar Via documentOpen

M

Mike

I am trying to add a menu item to Visio's menu bar. I want to create it
as the document opens and then delete as the document closes.

I have successfully created the menu item with the below sub. However
when I call this sub from Visio's document_documentOpen routine the
menu item is created, but then mysteriously deleted before the document
is fully open. In fact you can see the menu item popup and then
disappear!

Here's the sub that creates the menu item:

Sub addMenuBarItem()
On Error GoTo Error_addMenu

With Application.CommandBars.ActiveMenuBar.Controls
With .Add(Type:=msoControlPopup, before:=.Item("Help").Index,
temporary:=False)
.Caption = "SCOT Utilities"
With .Controls.Add
.Caption = "Re Load Date Picker"
.OnAction = "'" & ThisDocument.Name & "'!loadDatePicker"
End With
With .Controls.Add
.Caption = "Re Activate XLS Link"
.OnAction = "'" & ThisDocument.Name & "'!activateShts"
End With
End With
End With

Exit_addMenu:
On Error Resume Next
Exit Sub

Error_addMenu:
MsgBox "error adding menu item to visio - see VBA routine addMenu()"
GoTo Exit_addMenu

End Sub

And Here's the document_documentOpen routine:

Public Sub Document_DocumentOpened(ByVal voDoc As Visio.Document)
On Error GoTo ErrorAuto_Open

'loads menubar item for date picker and sheet re-activation
Call addMenuBarItem

ExitAuto_Open:
On Error Resume Next
Exit Sub
ErrorAuto_Open:
Resume ExitAuto_Open
End Sub

If anyone has a suggestion or knows this to be a bug in Visio - Thanks!


-Mike
 
J

junethesecond

Your program has no problem in my PC.
I've changed
OnAction = "'" & ThisDocument.Name & "'!loadDatePicker" and another line
like this
into
OnAction = "loadDatePicker", or so,
because of error message.
and add a dummy macro of loadDatePicker and so in a standard module.
 
M

Mike

junethesecond said:
Your program has no problem in my PC.
I've changed
OnAction = "'" & ThisDocument.Name & "'!loadDatePicker" and another line
like this
into
OnAction = "loadDatePicker", or so,
because of error message.
and add a dummy macro of loadDatePicker and so in a standard module.

Thanks!

I'm not sure what the problem is, but several of us have it. Anyways, I
suspected my code had to be close to correct and that something else
was interferring. I will try doing nothing else in the doc open
routine, but the menu bar and see if that works.
 
A

andrewLLL

Hi June,

Which version of Visio are you using June? I am sure I
experienced the same thing as Mike did, which the added
menus were disappeared after created using the Commandbars
object.

My workaround is to switch back to use the old Visio way of
using UIObject (and SetCustomMenus) and it worked, although
not the perfect way.

Andrew
 

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