J
Johann
Hi!
I am trying to add a custom item to the menu bar in Excel
when a specific workbook opens, with code as listed
below. The code runs without problems if I execute it
after the workbook has been opened, but I get an error
message if I paste and run the code in the Workbook_Open
procedure. Error message is typical Error 438 or Object
variable not set. I have tried to declare the variable at
a few different places with no luck. Any suggestions?
Johann
Code extract ************
Sub Macro2()
Dim VWSMenu As Object
Dim VWSSub1 As Object
Dim VWSSub2 As Object
Set VWSMenu = CommandBars("Worksheet Menu Bar").Controls.
Add(Type:=msoControlPopup, Before:=11, Temporary:=True)
With VWSMenu
.Caption = "VWS &Menu"
End With
Set VWSSub1 = CommandBars("Worksheet Menu Bar").Controls
("VWS Menu")
With VWSSub1
.Controls.Add(Type:=msoControlPopup,
Before:=1).Caption = "Leads List"
End With
etc.**************
I am trying to add a custom item to the menu bar in Excel
when a specific workbook opens, with code as listed
below. The code runs without problems if I execute it
after the workbook has been opened, but I get an error
message if I paste and run the code in the Workbook_Open
procedure. Error message is typical Error 438 or Object
variable not set. I have tried to declare the variable at
a few different places with no luck. Any suggestions?
Johann
Code extract ************
Sub Macro2()
Dim VWSMenu As Object
Dim VWSSub1 As Object
Dim VWSSub2 As Object
Set VWSMenu = CommandBars("Worksheet Menu Bar").Controls.
Add(Type:=msoControlPopup, Before:=11, Temporary:=True)
With VWSMenu
.Caption = "VWS &Menu"
End With
Set VWSSub1 = CommandBars("Worksheet Menu Bar").Controls
("VWS Menu")
With VWSSub1
.Controls.Add(Type:=msoControlPopup,
Before:=1).Caption = "Leads List"
End With
etc.**************