Macro won't run when button is clicked

crussom1

New Member
Joined
Jan 28, 2014
Messages
4
So I have a macro that works fine when I go to Developer tab > Macros > (select the macro) > Run. But then I assigned the macro to a button (I tried a rectangle shape first, then a form control button - both were the same), it gives me an error when I click the button. The error says "Cannot run the macro "p-5100.xlsm'!GoalFormat2'. The macro may not be available in this workbook or all macros may be disabled". The macro is definitly in the workbook because I can run it from the Developer tab and macros are enabled (there is another macro which runs automatically upon a selection change event which works fine...) The macro is supposed to let people select some cells within a specific range, then press a button to turn them green (I know this is kind of silly because this is like a one-click thing anyway but it is part of a larger project). The really odd thing is it works fine when I run it myself through the developer tab but not when I click the button. The button worked before when I was using 2007 (In fact files I already created with the button in them still work), but new files created from this template in 2013 have the problem.
Code:
Sub GoalFormat2()
If Not Intersect(Range("I25:O29"), Selection) Is Nothing Then
    'Change all the cells from column I to O in that row to white
    Range("I" & ActiveCell.Row & ":O" & ActiveCell.Row).Interior.Color = 16777215
    'Change the selected cells to green
    Selection.Interior.ThemeColor = xlThemeColorAccent3
End If
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
When you run it via the Developer tab and the Macro dialog box opens, have you selected "This Workbook" in the Macros in: drop down menu? When you assigned the macro to your button, was this drop down activated first?
 
Last edited:
Upvote 0
When you run it via the Developer tab and the Macro dialog box opens, have you selected "This Workbook" in the Macros in: drop down menu? When you assigned the macro to your button, was this drop down activated first?
Yes. At first it wasn't specifically set to 'This Workbook' but then later I tried to 'assign macro' again to the button and I closed all the other open workbooks, and chose 'This Workbook' from the drop down. It is very odd because it is starting to seem like this has something to do with me working with 2013 on my work computer - because the macro was working fine from home where I was using 2007. But when I create a new file with this template at work, the macro doesn't work when I click the button (even if I re-assign the macro), but it does work if run it myself.
 
Upvote 0
I have this same exact problem. I had buttons set up and they were working great until some time in the last month. I don't have any idea what changed but my macro ribbon panel buttons no longer work. I can run the macros from developer. I'm wondering if the personal.xlsb no longer loads properly.
 
Upvote 0
I found this thread while searching for a solution to a similar problem. I have a macro with the hot key combination Crtl+Shift+I to create invoices. When I use the key combination the macros starts, then freezes part way through. However if I run the macro through the developer tab it executes flawlessly.
 
Upvote 0
Has anyone ever come up with a solution to this problem?

I have a smiley button on my ribbon to which I assigned this macro, and it shows in Excel 2013 that it is assigned, but when I click it, nothing. Does anyone know what the deal is?



 
Upvote 0
Happened to me also.
I just saved the workbook, closed and reopened it.
it worked fine after that.
 
Upvote 0
I noticed this occurred when the macro accessed various worksheets (tabs) within the workbook. When I first recorded the macro, I started in the worksheet where most of the "work" the macro was doing occurred. But, I placed the button in a separate worksheet, assigned the macro, and would get an error when trying to run it.

When I re-recorded the macro, I started from the worksheet where the button was located and it worked fine.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,958
Members
449,200
Latest member
indiansth

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