Context menu will not invoke subroutine

JONeill

Board Regular
Joined
Sep 2, 2018
Messages
58
I have a context menu that shows when the user right-clicks on the worksheet. When I added a 10th item to it, the menu option shows up but it will not call the sub that calls the module that writes the report. Checked the syntax and created a breakpoint at the menu item being called for both the new option and a working one. The code will just not run. Here is the code.

Code:
Set myItem = myBar.Controls.Add(Type:=msoControlButton)
    With myItem
       .Caption = "Base Hours Estimate..."
       .OnAction = "HoursEstimateReport"
       .FaceId = 4
       'Indicate a new "group" by inserting a line.
       '.BeginGroup = True
    End With


'********************************************
'*          HoursEstimateReport()
'*
'* Creates the hours estimate report for the
'* current schedule.
'********************************************
Sub HoursEstimateReport()
     Dim actSheet As Worksheet
     MsgBox "HoursEstimateReport"
     
    'Set to active sheet
    Set actSheet = Application.ActiveSheet
    
    'If the current sheet is the cover sheet then
    'show error message
    If actSheet.name = FRONT_END_SHEET Then
        MsgBox "You must be on a schedule sheet to generate this report...", vbInformation, "Can't Generate Report"
    Else
        'Generate the report
        HoursEstimateReport.WriteReport
    End If
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Does anything at all happen when you click the menu item?
 
Upvote 0
I right click and the menu comes up and the item is added but nothing will happen when I click on it.
 
Upvote 0
Do other items you have added work properly?
 
Upvote 0
Not the new one or a one I did as a test. Those two don't work. All the others do. I don't imagine there's a limit to how many items you can put on there. At least not the number of items I have.
 
Upvote 0
So you have other items that you are adding that do work? If so, try changing the order of the items so that the one that isn't working is at the start - does it work then? (Like you, I'm not aware of a limit).

Which version of Excel are you using? If it's 2010 or later, you should really use the CustomUI part of the workbook to alter the context menus.
 
Upvote 0
I'm working in 2013 but the macro will be run in 2007. I've noticed since I started doing this that sometimes a module will get corrupted. I'm wondering if I just shouldn't create a new menu module and copy the old code to it.
 
Upvote 0
I put that menu item first but the same thing is happening. On all working procedure calls, breakpoints work in the menu module but not on the 2 that I added. The proc just never gets called.
 
Upvote 0
Which module is the HoursEstimateReport in?
 
Upvote 0
I realized what it was. I had an ambiguous name but there was no runtime error that popped up. The module containing the report had the same name as the sub in the menu module. Everything seems to be working now. Thanks for taking the time to help, though.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top