Shortcut Key for Macro Returns "Cannot Run the Macro..." Error

ransomedbyfire

Board Regular
Joined
Mar 9, 2011
Messages
121
I have made a shortcut key to run a macro. But, whenever I use the shortcut key, I get an error message that says Excel cannot run the macro. I also get a security warning saying that "Some active content has been disabled."

I have tried using "Application.EnableEvents"; but this does not help. I ran into this same problem a few days ago and managed to fix it; but now I can't remember how. Please help!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Could be that your code, at the moment it gets executed, is in conflict with something else, such as if it relies on an active cell moving 3 columns to the left, but your active cell is in column A, that would cause an error. Not necessarily the error you are receiving, but if you post your code that woudl help people reading this to guide you to a possible solution.
 
Upvote 0
Here is the code that activates the keys
Code:
Private Sub Workbook_Open()

Application.EnableEvents = True

'Checks to see if the spreadsheet is the original or a copy
namestring = ThisWorkbook.Name
findstring = Year(Date)

'Sets calculation to manual if workbook is a copy
If InStr(1, namestring, findstring) > 0 Then
    Application.Calculation = xlCalculationManual

'Sets calculation to auto if not a copy
    Else: Application.Calculation = xlCalculationAutomatic

'Activates keyboard shortcuts if not a copy
    Application.OnKey "^+G", "Green"
    Application.OnKey "^+W", "White"

    Call ftdatecheck
    
End If

End Sub
Here are the macros that the keys are supposed to call
Code:
Public Sub white()

If ActiveSheet.Name = "Owned" Then
    Row = ActiveCell.Row
    Range("A" & Row).Interior.ColorIndex = 0
    Range("H" & Row & ":L" & Row).Interior.ColorIndex = 0
End If

End Sub
Code:
Sub green()

If ActiveSheet.Name = "Owned" Then
    Row = ActiveCell.Row
    Range("A" & Row).Interior.ColorIndex = 35
    Range("H" & Row & ":L" & Row).Interior.ColorIndex = 35
End If

End Sub
 
Upvote 0
Okay. I think I fixed it. For anyone else who may ever have the same problem, here is what I did.

1. Delete the "onkey" codes.
2. Restart Excel.
3. Re-assign the shortcut keys via the Macros button in the developer tab.

You must make sure the onkey codes are no longer affecting your spreadsheet, or you will continue to get the same error.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,818
Members
452,946
Latest member
JoseDavid

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