Q
quartz
I am using Office 2003 on Windows XP. The following function adds two custom
button controls to the top of every shortcut menu. This runs using an
"OnActivate" event and runs great. Except for one small but annoying thing. I
want a "BeginGroup" line to separate my custom items from the rest of the
built-in menu choices.
But, when I enter a line of code to include this, it errors out. This line
is noted below and also included below for your convenience is a function to
reset your shortcut menus to normal. Can someone please correct my code so it
will work right?
Public Function ShortCutMenuModify()
Dim cbBar As CommandBar
Dim lX As Long
For lX = 1 To Application.CommandBars.Count
If CommandBars(lX).Type = msoBarTypePopup And CommandBars(lX).BuiltIn =
True Then
Set cbBar = Application.CommandBars(lX)
With cbBar
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "GOTO"
.Controls(1).FaceId = 5828
.Controls(1).OnAction = "RunFOREIGN"
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "PRINT"
.Controls(1).FaceId = 5828
.Controls(1).OnAction = "RunFOREIGN"
'THE FOLLOWING LINE CAUSES AN ERROR, WHY? - HOW FIX?
If .Controls.Count > 4 Then .Controls(3).BeginGroup = True
End With
End If
Next lX
End Function
RUN THE FOLLOWING TO RESET ALL MENUS (This runs fine but is included for
your convenience):
Public Function ShortCutMenuReset()
'RESET EXCEL'S BUILT-IN RIGHT-CLICK SHORTCUT MENU: CALLED ON WORKBOOK
DEACTIVATE
Dim cmdBar As CommandBar
Dim lngX As Long
For lngX = 1 To Application.CommandBars.Count
If CommandBars(lngX).Type = msoBarTypePopup And
CommandBars(lngX).BuiltIn = True Then CommandBars(lngX).Reset
Next lngX
End Function
button controls to the top of every shortcut menu. This runs using an
"OnActivate" event and runs great. Except for one small but annoying thing. I
want a "BeginGroup" line to separate my custom items from the rest of the
built-in menu choices.
But, when I enter a line of code to include this, it errors out. This line
is noted below and also included below for your convenience is a function to
reset your shortcut menus to normal. Can someone please correct my code so it
will work right?
Public Function ShortCutMenuModify()
Dim cbBar As CommandBar
Dim lX As Long
For lX = 1 To Application.CommandBars.Count
If CommandBars(lX).Type = msoBarTypePopup And CommandBars(lX).BuiltIn =
True Then
Set cbBar = Application.CommandBars(lX)
With cbBar
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "GOTO"
.Controls(1).FaceId = 5828
.Controls(1).OnAction = "RunFOREIGN"
.Controls.Add Type:=msoControlButton, Before:=1
.Controls(1).Caption = "PRINT"
.Controls(1).FaceId = 5828
.Controls(1).OnAction = "RunFOREIGN"
'THE FOLLOWING LINE CAUSES AN ERROR, WHY? - HOW FIX?
If .Controls.Count > 4 Then .Controls(3).BeginGroup = True
End With
End If
Next lX
End Function
RUN THE FOLLOWING TO RESET ALL MENUS (This runs fine but is included for
your convenience):
Public Function ShortCutMenuReset()
'RESET EXCEL'S BUILT-IN RIGHT-CLICK SHORTCUT MENU: CALLED ON WORKBOOK
DEACTIVATE
Dim cmdBar As CommandBar
Dim lngX As Long
For lngX = 1 To Application.CommandBars.Count
If CommandBars(lngX).Type = msoBarTypePopup And
CommandBars(lngX).BuiltIn = True Then CommandBars(lngX).Reset
Next lngX
End Function