Keyboard shortcut not working for a macro

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
301
Office Version
  1. 365
I'm having trouble getting a macro to run when I press a key combination.


This code sets the worksheets to VeryHidden:


Code:
Sub DeliveryPrep()
    Worksheets("Leader Info").Visible = xlVeryHidden
    Worksheets("Calculations").Visible = xlVeryHidden
    Worksheets("Details").Visible = xlVeryHidden
    Worksheets("Dynamic Records").Visible = xlVeryHidden
    Worksheets("Email").Visible = xlVeryHidden
    Worksheets("GhostData").Visible = xlVeryHidden
    Worksheets("PivotData").Visible = xlVeryHidden
End Sub

I then went into the Macro dialog (not VBA) to assign a shortcut: Ctrl+Shift+O. This works.


But I also created the reverse of the code above to make those pages visible:


Code:
Sub MakeSheetsVisible()
    Worksheets("Leader Info").Visible = xlVisible
    Worksheets("Calculations").Visible = xlVisible
    Worksheets("Details").Visible = xlVisible
    Worksheets("Dynamic Records").Visible = xlVisible
    Worksheets("Email").Visible = xlVisible
    Worksheets("GhostData").Visible = xlVisible
    Worksheets("PivotData").Visible = xlVisible
End Sub

The shortcut for this one is Ctrl+Shift+L. This does NOT work. Instead, I get an error message:

Run-time error '1004':
Unable to set the Visible property of the Worksheet class


What am I missing here please?
 

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
Can you manually run the MakeSheetsVisible macro without that error occurring?
 
Upvote 0
<code>Try repacing xVisible with </code><code class="vb plain">xlSheetVisible</code>
 
Upvote 0
Thanks jmacleary and RoryA. jmacleary nailed it.

But but now I realized that I need to make it private which, at least from my testing, doesn't make them respond to the keyboard shortcuts.


I've looked at KeyDown and OnKey, but it's still a bit confusing.


I don't want to remap any keys, just have the macros execute when I press Ctrl+Shift+O and Ctrl+Shift+L.


Do you have any suggestions?
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,929
Members
449,479
Latest member
nana abanyin

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