create a menu button to run VBA app
create a menu button to run VBA app
(OP)
I created VBA program now how do I make a menu button to launch it. instead of clicking Tools, Macros etc etc
DougP < I love mine
www.robots2000.com
RE: create a menu button to run VBA app
Put the following code into its own code module, and run the "Menu main" command. It creates a new, top level menu, and 4 sub menus. You'll want to change the name of the Main menu ("My&Menu"), the name(s) of the Sub menus("My&SubMenu"), and the names of the subroutine(s) called "TestSub" to the names of your own subroutines, to fit your application.
' ---- snip ----- snip ---- snip ----- snip ----
Sub MenuMain()
Dim retMenu As AcadPopupMenu
Dim retMenuItem As AcadPopupMenuItem
Const MainMenuName As String = "My&Menu" ' add an Ampersand in front of letter to make it a Hotkey
Const SubMenuName As String = "My&SubMenu"
' either add new, or return existing main menu Item
Set retMenu = AddMainMenu(MainMenuName) '' add (or GET) main menu item
' add some sub menu item to our main menu
For I% = 1 To 4
Set retMenuItem = AddMainMenuItem(retMenu, SubMenuName & Str$(I%), "TestSub")
Next '
End Sub
Private Function AddMainMenu(strMenuName As String) As AcadPopupMenu
' adds a main menu to acad menus, or returns an existing menu with the same name
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item("ACAD")
For I = 0 To currMenuGroup.Menus.Count - 1
If currMenuGroup.Menus(I).Name = strMenuName Then
Set AddMainMenu = currMenuGroup.Menus(I)
Exit Function
End If
Next
' if we're still here, we didnt find the menu, so we'll add one
Set AddMainMenu = currMenuGroup.Menus.Add(strMenuName)
' Display the menu on the menu bar
AddMainMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)
End Function
Private Function AddMainMenuItem(objMenu As AcadPopupMenu, strMenuItem As String, strMacroName As String) As AcadPopupMenuItem
' adds a sub menu item to the passed menu object
' the "strMenuIte" param is the name of ther menu, per VB xconvention, embed an ampersand "&"
' before the letter you want to be a hotkey
' The "strMacroName" is the name of the Subroutine you want called when the menu is selected
Dim openMacro As String
openMacro = "-VBARUN " & strMacroName & " " ' add a space to enmnu item to emulate the ENTER key]'
Set AddMainMenuItem = objMenu.AddMenuItem(objMenu.Count + 1, strMenuItem, openMacro)
End Function
Sub TestSub()
' name of routine to call when menu item is selected
MsgBox "your menu was just selected"
End Sub
' ---- snip ----- snip ---- snip ----- snip ----
RE: create a menu button to run VBA app
I would rather have a button on a toolbar so I don't have to click a menu or go that far up and then a submenu. I want to just click a button on the side. I have tons of buttons already, some use Lisp most are just ??? commands strung together. With LISP you load it then put the name in the button. VBA does not work like that for some reason. I loaded it but a button with the following says Unknown command.
CODE
my VBA dvd is called ListChainCustody.dvd it has a form that pops up if I hit the run button in the VBA IDE.
Also, how do I get rid of the My Menu I just created.
DougP
< I love mine
www.robots2000.com
RE: create a menu button to run VBA app
I saw this is your example above
VBARUN " & strMacroName &
I added it to a button.
^C^C-vbarun ListChainCustody
and when I click it I get this message which I copied from the command line
Command: -vbarun
Macro name: ListChainCustody
Macro not found.
If I click the "tools" menu then "load appication" it show in the Loaded list and history and if I click load it says its already loaded.
DougP
< I love mine
www.robots2000.com
RE: create a menu button to run VBA app
You need to tell the vbarun functionality where the macro can be found:
CODE
or
CODE
etc.
HTH
Todd
RE: create a menu button to run VBA app
I created a Module and in it a sub called LoadChainOfCustody
CODE
'this sub is necessary to load the form
frmChainOfCustody.Show
End Sub
Then using your code, my button has this in the "Macro associated with this button:
CODE
DougP
< I love mine
www.robots2000.com
RE: create a menu button to run VBA app
DougP
< I love mine
www.robots2000.com
RE: create a menu button to run VBA app
http://forums.augi.com/showthread.php?t=55292