Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a drop down list in my quick links menu that runs different macros or opens different spreadsheets. It was from John Walkenbach or some one else. I do not remember any more as I have had it for many years now.
My question is, is there some code that will give me the name of the macro that was just called when I click on one of the list items from the quick links drop down this code created? Example: (Quicklinks drop down list) List of standard part types -Bearings -Tires -Engines -Bolts If I click on the list item "-Bearings" it has a macro associated to it called "Std_Parts_Bearings" and in the macro I have the link to that spreadsheet. How can I get the name of the link/menu item "-Bearings" that I clicked on that calls the "Std_Parts_Bearings" macro? Thanks Scott Menu Maker for the quick links bar: Option Explicit Sub CreateMenu() ' This sub should be executed when the workbook is opened. ' NOTE: There is no error handling in this subroutine Dim MenuSheet As Worksheet Dim MenuObject As CommandBarPopup Dim MenuItem As Object Dim SubMenuItem As CommandBarButton Dim Row As Integer Dim MenuLevel, NextLevel, PositionOrMacro, Caption, Divider, FaceId Dim myMenuCtl As CommandBarControl Dim Counter As Integer '''''''''''''''''''''''''''''''''''''''''''''''''' '' ' Location for menu data Set MenuSheet = ThisWorkbook.Sheets("MenuSheet") '''''''''''''''''''''''''''''''''''''''''''''''''' '' ' Make sure the menus aren't duplicated Call DeleteMenu ' Initialize the row counter Row = 2 ' Add the menus, menu items and submenu items using ' data stored on MenuSheet Do Until IsEmpty(MenuSheet.Cells(Row, 1)) With MenuSheet MenuLevel = .Cells(Row, 1) Caption = .Cells(Row, 2) If IsNumeric(.Cells(Row, 3)) Then 'Find the last command bar index # if adding another command bar For Each myMenuCtl In Application.CommandBars("Worksheet Menu Bar").Controls Counter = myMenuCtl.Index Next myMenuCtl If .Cells(Row, 3) Counter Then PositionOrMacro = Counter + 1 End If Else PositionOrMacro = .Cells(Row, 3) 'Used to set Macro assignment End If Divider = .Cells(Row, 4) FaceId = .Cells(Row, 5) NextLevel = .Cells(Row + 1, 1) End With Select Case MenuLevel Case 1 ' A Menu ' Add the top-level menu to the Worksheet CommandBar Set MenuObject = Application.CommandBars(1). _ Controls.Add(Type:=msoControlPopup, _ Befo=PositionOrMacro, _ temporary:=True) MenuObject.Caption = Caption Case 2 ' A Menu Item If NextLevel = 3 Then Set MenuItem = MenuObject.Controls.Add(Type:=msoControlPopup) Else Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = PositionOrMacro End If MenuItem.Caption = Caption If FaceId < "" Then MenuItem.FaceId = FaceId If Divider Then MenuItem.BeginGroup = True Case 3 ' A SubMenu Item Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.Caption = Caption SubMenuItem.OnAction = PositionOrMacro If FaceId < "" Then SubMenuItem.FaceId = FaceId If Divider Then SubMenuItem.BeginGroup = True End Select Row = Row + 1 Loop End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Moving 2003 Custom Menu to Quick Access Toolbar | Excel Programming | |||
a quick way to determine the first and last biz date of the month | Excel Programming | |||
How to create a standard Quick Launch menu in Excel 2007 | Excel Programming | |||
DP adjustment using quick menu buttons when sheet protected | Excel Worksheet Functions | |||
How to determine links to external files or spreadsheets | Excel Programming |