G
Guest
I used the code from the book Power Programming by Walkenbach to make a new menu upon opening a certain workbook. However, I get the following error message "Run Time Error '91'. Object variable or With block variable not set" and it highlights the line of code that is "Set HelpMenu = CommandBars(1).FindControl(ID:=30010)"
Can you help? Here is the code
Sub CreateMenu(
Dim NewMenu As CommandBarPopu
' Delete the menu if it already exist
Call DeleteMen
' Find the Help Men
Set HelpMenu = CommandBars(1).FindControl(ID:=30010
If HelpMenu Is Nothing The
' Add the menu to the en
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup,
temporary:=True
Els
' Add the menu before Hel
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup,
Before:=HelpMenu.Index,
temporary:=True
End I
' Add a caption for the men
NewMenu.Caption = "&Budgeting
' FIRST MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton
With MenuIte
.Caption = "&Data Entry...
.FaceId = 16
.OnAction = "Macro1
End Wit
' SECOND MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton
With MenuIte
.Caption = "&Generate Reports...
.FaceId = 59
.OnAction = "Macro2
End Wit
' THIRD MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlPopup
With MenuIte
.Caption = "View &Charts
.BeginGroup = Tru
End Wit
' FIRST SUBMENU ITE
Set SubMenuItem = MenuItem.Controls.Add
(Type:=msoControlButton
With SubMenuIte
.Caption = "Monthly &Variance
.FaceId = 42
.OnAction = "Macro3
End Wit
' SECOND SUBMENU ITE
Set SubMenuItem = MenuItem.Controls.Add
(Type:=msoControlButton
With SubMenuIte
.Caption = "Year-To-Date &Summary
.FaceId = 42
.OnAction = "Macro4
End Wit
End Sub
Can you help? Here is the code
Sub CreateMenu(
Dim NewMenu As CommandBarPopu
' Delete the menu if it already exist
Call DeleteMen
' Find the Help Men
Set HelpMenu = CommandBars(1).FindControl(ID:=30010
If HelpMenu Is Nothing The
' Add the menu to the en
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup,
temporary:=True
Els
' Add the menu before Hel
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup,
Before:=HelpMenu.Index,
temporary:=True
End I
' Add a caption for the men
NewMenu.Caption = "&Budgeting
' FIRST MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton
With MenuIte
.Caption = "&Data Entry...
.FaceId = 16
.OnAction = "Macro1
End Wit
' SECOND MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton
With MenuIte
.Caption = "&Generate Reports...
.FaceId = 59
.OnAction = "Macro2
End Wit
' THIRD MENU ITE
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlPopup
With MenuIte
.Caption = "View &Charts
.BeginGroup = Tru
End Wit
' FIRST SUBMENU ITE
Set SubMenuItem = MenuItem.Controls.Add
(Type:=msoControlButton
With SubMenuIte
.Caption = "Monthly &Variance
.FaceId = 42
.OnAction = "Macro3
End Wit
' SECOND SUBMENU ITE
Set SubMenuItem = MenuItem.Controls.Add
(Type:=msoControlButton
With SubMenuIte
.Caption = "Year-To-Date &Summary
.FaceId = 42
.OnAction = "Macro4
End Wit
End Sub