PDA

View Full Version : Calling VBA Methods from Menus


MrB
28-10-2005, 03:03 PM
Hi

I've copied one of the samples that comes with AutoCad 2004 to add a custom menu set under Modify. These appear ok but I can't work out how to format the command to get the menu option to run another of my methods in the VBA project.

code snippet:

For Each oPopup In oAcad.MenuBar
'TagString is not localized so use it to locate the menu
If oPopup.TagString = "ID_MnModify" Then
Set oSubPopup = oPopup.AddSubMenu(0, "Windchill")
'set TagString to a known value; we'll use this during removal
oSubPopup.Parent.TagString = "ID_MyModify"
Set oPopupMenuItem = oSubPopup.AddMenuItem(0, "Login", "Project.SchematicModule.ShowLoginDialog")

If I use the above, nothing happens, if I try to prefix it with vbarun then I get a dialog box popping up for me to select a method from. There has to be a simple format for this "Macro As string" argument that does this... Anyone know what it is?

Thanks and regards

Ian

Eddie
30-10-2005, 08:50 PM
If you wnat to have a button run your VBA macro then place something like this in the button code...

^C^C-vbarun;myfunction;

MrB
02-11-2005, 04:29 PM
Hi

Eventually got it working... solution is:

Set oPopupMenuItem = oSubPopup.AddMenuItem(0, "Something", "_-VBARUN Project.SchematicModule.ShowLoginDialog" + Chr(13))

the "_-" stops the Macro selector and the Chr(13) is effectively the same as hitting the Enter key. Messy but it works!!

Ian