Yet Another Problem2 when VBA is in the Stencil (instead of Docume

M

mikeFin

Sorry for posting again. I tried finding the solution on my own and by
searching the web, but it do not see what's wrong.
When I had the following VBA code stored in the document, it did work.
Now that it is in the stencil, the menu does build, but the Menu-Item is
greyed-out.

Here is the code:

- - -

Sub new_menu()

Dim appVisio As Visio.Application
Dim UIObj As Visio.UIObject 'Contains the UI object
Dim menuSetsObj As Visio.MenuSets 'MenuSets collection
Dim menuSetObj As Visio.MenuSet 'A MenuSet object
Dim menusObj As Visio.Menus 'Menus collection
Dim menuObj As Visio.Menu 'A Menu object
Dim menuItemsObj As Visio.MenuItems 'MenuItems collection
Dim menuItemObj As Visio.MenuItem 'A MenuItem object

Set appVisio = Visio.Application
Set UIObj = appVisio.BuiltInMenus
Set menuSetsObj = UIObj.MenuSets
Set menuSetObj = menuSetsObj.ItemAtID(visUIObjSetDrawing)
Set menusObj = menuSetObj.Menus
Set menuObj = menusObj.AddAt(7)
menuObj.Caption = "&My Menu"

Set menuItemsObj = menuObj.MenuItems

Set menuItemObj = menuItemsObj.Add
With menuItemObj
.Caption = "&My Menu Item1"
.CmdNum = 0
.AddOnName = "myProc1"
.Enabled = True
End With

ActiveDocument.SetCustomMenus UIObj

End Sub

- - -

I guess it is because of:
.AddOnName = "myProc1"
I already tried changing it to "StencilName!moduleName.myProc1", but it
doesn't seem to help.

I hope this was the last question of that sort.

Thanks !
 
J

JuneTheSecond

mikeFin,

I recommend you to use CommandBarControl inplace of UIObject.
The format to run macro in another project is
ctrl1.OnAction = "ProjectnameOfStencil!ModuleName.MacroName"
The delimitter for project name and module name is "!",
for modilename and macro name is "."

In UIObject if macro is in Module1 and the reference
from drawing to the stencil is set, then
MenuItemObj.AddOnName="MacroName"
runs correctly.
But it seems macro is in ThisDocument
macro cannot starts.

--
Best Regards
JuneTheSecond

Now, visual calculation is more visual.
http://www.geocities.jp/visualcalculation/english/index.html
 
M

mikeFin

Hello JuneTheSecond,

I am still not able to make it work.

..AddOnName = "ProjectName.ThisDocument.myProc1"

doesnt want to work, at least not, when ProjectName is the ProjectName of my
stencil.
I want to try to have all my VBA-Code in one stencil. I prefer having it in
a module of the stencil. But if something only works from TheDocument of the
stencil it is also ok.
So the menu is in the module of stencil, and also the procedure I want to
call is in the stencil (the same one; all my VBA-Code is in this stencil)

I tried:

..AddOnName = "StencilProjectName!ThisDocument.myProc1"
..AddOnName = "StencilProjectName.ThisDocument.myProc1"
..AddOnName = "ThisDocument.myProc1"

..AddOnName = "StencilProjectName!module1.myProc2"
..AddOnName = "StencilProjectName.module1.myProc2"
..AddOnName = "module1.myProc2"

Thanks for the appreciated help!
 
M

mikeFin

Hello again!

I followed your other advice and use CommandBarControl instead of UIObject.
Now it works fine!!!

I would be desperate without you...
THANKS!!
 
P

Paul Herber

Sorry for posting again. I tried finding the solution on my own and by
searching the web, but it do not see what's wrong.
When I had the following VBA code stored in the document, it did work.
Now that it is in the stencil, the menu does build, but the Menu-Item is
greyed-out.

Here is the code:

- - -

Sub new_menu()

Dim appVisio As Visio.Application
Dim UIObj As Visio.UIObject 'Contains the UI object
Dim menuSetsObj As Visio.MenuSets 'MenuSets collection
Dim menuSetObj As Visio.MenuSet 'A MenuSet object
Dim menusObj As Visio.Menus 'Menus collection
Dim menuObj As Visio.Menu 'A Menu object
Dim menuItemsObj As Visio.MenuItems 'MenuItems collection
Dim menuItemObj As Visio.MenuItem 'A MenuItem object

Set appVisio = Visio.Application
Set UIObj = appVisio.BuiltInMenus

You should really check whether CustomMenus exists first.
 

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