![]() |
Add "BeginGroup" to customized shortcut menus
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, Befo=1 .Controls(1).Caption = "GOTO" .Controls(1).FaceId = 5828 .Controls(1).OnAction = "RunFOREIGN" .Controls.Add Type:=msoControlButton, Befo=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 |
Add "BeginGroup" to customized shortcut menus
Works for me. What is the error message?
-- Vasant "quartz" wrote in message ... 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, Befo=1 .Controls(1).Caption = "GOTO" .Controls(1).FaceId = 5828 .Controls(1).OnAction = "RunFOREIGN" .Controls.Add Type:=msoControlButton, Befo=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 |
All times are GMT +1. The time now is 02:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com