SimonHA
03-05-2013, 03:23 PM
Hello everyone,
I'm completely new to VBA and I'm trying to add a contextmenu with simple code from MSDN.
But I'm getting error BC30469: Reference to a non-shared member requires an object reference.
This appears at MyContext = Application.CommandBars("Cell")
What does that error mean?
Sub AddCellContext()
Dim MyContext As CommandBars
Dim MySubMenu As CommandBarControl
' Set MyConext to the Cell context menu.
MyContext = Application.CommandBars("Cell")
' Add one built-in button(Save = 3) to the Cell context menu.
MyContext.Controls.Add(Office.MsoControlType.msoControlButton, Id:=3, Before:=1)
' Add a custom submenu with three buttons.
MySubMenu = MyContext.Controls.Add(Office.MsoControlType.msoControlButtonPopup, Before:=3)
With MySubMenu
.Caption = "Test"
.Tag = "Cell_Test"
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 100
.Caption = "Test 1"
End With
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 91
.Caption = "Test 2"
End With
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 95
.Caption = "Test 3"
End With
End With
' Add a separator to the Cell context menu.
MyContext.Controls(4).BeginGroup = True
End Sub
Regards,
Simon H.A.
I'm completely new to VBA and I'm trying to add a contextmenu with simple code from MSDN.
But I'm getting error BC30469: Reference to a non-shared member requires an object reference.
This appears at MyContext = Application.CommandBars("Cell")
What does that error mean?
Sub AddCellContext()
Dim MyContext As CommandBars
Dim MySubMenu As CommandBarControl
' Set MyConext to the Cell context menu.
MyContext = Application.CommandBars("Cell")
' Add one built-in button(Save = 3) to the Cell context menu.
MyContext.Controls.Add(Office.MsoControlType.msoControlButton, Id:=3, Before:=1)
' Add a custom submenu with three buttons.
MySubMenu = MyContext.Controls.Add(Office.MsoControlType.msoControlButtonPopup, Before:=3)
With MySubMenu
.Caption = "Test"
.Tag = "Cell_Test"
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 100
.Caption = "Test 1"
End With
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 91
.Caption = "Test 2"
End With
With .Controls.Add(Office.MsoControlType.msoControlButton)
.FaceId = 95
.Caption = "Test 3"
End With
End With
' Add a separator to the Cell context menu.
MyContext.Controls(4).BeginGroup = True
End Sub
Regards,
Simon H.A.