Hallo,
Ik heb een probleem met het creeëren van een eigen menubar (ter vervanging van de bestaande menubar in Excel, je weet wel....die met Bestand, Bewerken, Beeld, etc...) voor 1 Excel-bestand.
Ik krijg de volgende foutmelding:
Compileerfout:
Een door de gebruiker gedefinieerd gegevenstype is niet gedefinieerd.
Wat doe ik fout????? HELP!!!!
Alvast bedankt.
Het gaat om: Dim My_Menu As CommandBar
Hierbij de volledige code:
Sub Create_A_New_Menu_System()
Dim My_Menu As CommandBar, newControl, newItem, subMenu
'remove custom menu if it exists
On Error Resume Next
CommandBars("New Menu System").Delete
On Error GoTo 0
'create new menu and display it
Set My_Menu = CommandBars.Add(Name:="New Menu System", _
Position:=msoBarTop, _
MenuBar:=False)
My_Menu.Visible = True
'add a menu to the new CommandBar
Set newControl = My_Menu.Controls.Add(Type:=msoControlPopup)
newControl.Caption = "Menu1"
'add a menu item to the new menu
With newControl
Set newItem = .Controls.Add(Type:=msoControlButton)
Set subMenu = .Controls.Add(Type:=msoControlPopup)
End With
With newItem
.Caption = "This Says Hello"
.OnAction = "SayHello"
End With
'add a sub menu to the new menu and add items to it
With subMenu
.Caption = "Additional Choices"
Set newItem = .Controls.Add(Type:=msoControlButton)
newItem.Caption = "Check On Fishing"
newItem.OnAction = "FishingStatus"
Set newItem = _
.Controls.Add(Type:=msoControlButton)
newItem.Caption = "Check On Golfing"
newItem.OnAction = "GolfingStatus"
End With
'add a menu item that will restore the original menus
Set newItem = _
newControl.Controls.Add(Type:=msoControlButton)
With newItem
.Caption = "Remove the new menu system"
.OnAction = "RemoveCustomMenu"
'This next statement adds a separator bar
.BeginGroup = True
End With
'add a menu to the new CommandBar
Set newControl = My_Menu.Controls.Add(Type:=msoControlPopup)
newControl.Caption = "Menu2"
Set newItem = newControl.Controls.Add(Type:=msoControlButton)
With newItem
.Caption = "Say Goodbye"
.OnAction = "SayGoodbye"
End With
End Sub
Sub SayHello()
MsgBox "Hello world"
End Sub
Sub SayGoodBye()
MsgBox "Goodbye!"
End Sub
Sub fishingStatus()
MsgBox "Fishing is great all the time!!!"
End Sub
Sub golfingStatus()
MsgBox "Who cares? I'd rather be fishing!"
End Sub
Sub RemoveCustomMenu()
CommandBars("New Menu System").Delete
End Sub
Ik heb een probleem met het creeëren van een eigen menubar (ter vervanging van de bestaande menubar in Excel, je weet wel....die met Bestand, Bewerken, Beeld, etc...) voor 1 Excel-bestand.
Ik krijg de volgende foutmelding:
Compileerfout:
Een door de gebruiker gedefinieerd gegevenstype is niet gedefinieerd.
Wat doe ik fout????? HELP!!!!

Het gaat om: Dim My_Menu As CommandBar
Hierbij de volledige code:
Sub Create_A_New_Menu_System()
Dim My_Menu As CommandBar, newControl, newItem, subMenu
'remove custom menu if it exists
On Error Resume Next
CommandBars("New Menu System").Delete
On Error GoTo 0
'create new menu and display it
Set My_Menu = CommandBars.Add(Name:="New Menu System", _
Position:=msoBarTop, _
MenuBar:=False)
My_Menu.Visible = True
'add a menu to the new CommandBar
Set newControl = My_Menu.Controls.Add(Type:=msoControlPopup)
newControl.Caption = "Menu1"
'add a menu item to the new menu
With newControl
Set newItem = .Controls.Add(Type:=msoControlButton)
Set subMenu = .Controls.Add(Type:=msoControlPopup)
End With
With newItem
.Caption = "This Says Hello"
.OnAction = "SayHello"
End With
'add a sub menu to the new menu and add items to it
With subMenu
.Caption = "Additional Choices"
Set newItem = .Controls.Add(Type:=msoControlButton)
newItem.Caption = "Check On Fishing"
newItem.OnAction = "FishingStatus"
Set newItem = _
.Controls.Add(Type:=msoControlButton)
newItem.Caption = "Check On Golfing"
newItem.OnAction = "GolfingStatus"
End With
'add a menu item that will restore the original menus
Set newItem = _
newControl.Controls.Add(Type:=msoControlButton)
With newItem
.Caption = "Remove the new menu system"
.OnAction = "RemoveCustomMenu"
'This next statement adds a separator bar
.BeginGroup = True
End With
'add a menu to the new CommandBar
Set newControl = My_Menu.Controls.Add(Type:=msoControlPopup)
newControl.Caption = "Menu2"
Set newItem = newControl.Controls.Add(Type:=msoControlButton)
With newItem
.Caption = "Say Goodbye"
.OnAction = "SayGoodbye"
End With
End Sub
Sub SayHello()
MsgBox "Hello world"
End Sub
Sub SayGoodBye()
MsgBox "Goodbye!"
End Sub
Sub fishingStatus()
MsgBox "Fishing is great all the time!!!"
End Sub
Sub golfingStatus()
MsgBox "Who cares? I'd rather be fishing!"
End Sub
Sub RemoveCustomMenu()
CommandBars("New Menu System").Delete
End Sub