Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Add-in for a menu for a macro

Status
Not open for further replies.

NightZEN

Programmer
Joined
Apr 29, 2003
Messages
142
Location
US
I am trying to create and add-in that will add a menu item for users to click and call a macro called "HotList_Formating". I have the following code saved in an add-in file (hotlist_formater.xla) in it's "ThisWorkbook" Object. I did not include the called subroutines here to save space, but they are saved in the same location. When I add the add-in and click the menu button I get the following error:

"The macro 'hotlist_formater.xla!HotList_Formating' cannot be found."

Why Not? Please help me to understand where I'm going wrong. Thanks!!!!!


Code:
Option Explicit
Dim cControl As CommandBarButton

Private Sub Workbook_AddinInstall()

    On Error Resume Next 'Just in case
    'Delete any existing menu item that may have been left.
    Application.CommandBars("Worksheet Menu Bar").Controls("HotList Formater").Delete
    'Add the new menu item and Set a CommandBarButton Variable to it
    Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
    'Work with the Variable
        With cControl
            .Caption = "HotList Formater"
            .Style = msoButtonCaption
            .OnAction = "'" & ThisWorkbook.Name & "'!HotList_Formating"
            'Macro stored in a Standard Module
        End With
        
    On Error GoTo 0
End Sub
Private Sub Workbook_AddinUninstall()
    
    On Error Resume Next 'In case it has already gone.
    Application.CommandBars("Worksheet Menu Bar").Controls("HotList Formater").Delete
    On Error GoTo 0
End Sub

Sub HotList_Formating()
'
' HotList_Formating Macro
' Changes a cell's color based on the workcenter.
'

'
   Call AddHeaderColor
   Call AddLines
   Call ChangeColor("M4:M2000")
   Call ChangeColor("J4:J2000")
   
End Sub
 
Move procedure HotList_Formating to a standard code module. If you don't already have one in your project, select Insert|Module from the main menu in the VB Editor.


Regards,
Mike
 
Alternatively, you can keep the HotList_Formating procedure where it is by qualifying the procedure name with ThisWorkbook:
Code:
.OnAction = "'" & ThisWorkbook.Name & "'!Thisworkbook.HotList_Formating"

I prefer to place most of my routines in standard code modules, however.


Regards,
Mike
 
That did it Mike, Thanks!
 
Nice piece of work. Don't suppose you could incorporate some of your energy into an Add-In? [thumbsup2]


Regards,
Mike
 
Thank you. And of course. I love making addnis. :)

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top