Activate Menu Items

G

Guest

You fix one thing another pops up! I've added a custom menu to a workbook
template. That work very well using event handlers Workbook_activate &
Workbook_deactivate in ThisWorkbook.
I can add menu items thru Auto_Open. Workbook_Deactivate deletes the item
when I jump over to the next workbook. The proplem that I'm having is that
when these Templates are saved in different names and open at the same time,
all the menu items disapper. First they disapper on the inactive workbook,
then when you click over to the inactive the other menu items disapper.
Below is the code:

Sub Auto_Open()
Dim Item As CommandBarControl
Set Item = CommandBars(1).Controls("Custom") _
.Controls.Add
Item.Caption = "&AllenPark"
Item.OnAction = "AllenPark"
Item.BeginGroup = True
End Sub

Sub Workbook_Deactivate()
On Error Resume Next
CommandBars(1).Controls("Custom").Controls("&AllenPark").Delete
End Sub
Sub AllenPark()
MsgBox "This is a do-nothing macro.", vbInformation, "AllenPark"
End Sub

Does anyone know a way to get around this? A way to get the menu items to
appear everytime the workbook becomes active? I guess the diasppearing works
ok.
 
G

Guest

Sorry, i just figured out the answer for my previous answer. I could use
Call AddMenuItem from ThisWorkbook.

An additional questions that arises is how to add more than one menu item? I
have a VBA book, but it only had how to add just one menu item. Below is the
code that I'm using to add the menu item:

Sub AddMenuItem()
Dim Item As CommandBarControl
Set Item = CommandBars(1).Controls("Custom") _
.Controls.Add
Item.Caption = "&AllenPark"
Item.OnAction = "AllenPark"
Item.BeginGroup = True
End Sub


Any help would be greatly appreciated.
Thanks
Renato
 

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