Hiding macros

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have created a menu on my spreadsheet. I want the user to only run my macros from this menu. How can I disable the Tools Macro Run

I do have a password on the VBA project so that the macros cannot be edited by they can still be run.

Thanks
L
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
This can be done in a few ways, the easy way is to use Control Toolbox Buttons to Run your code. The View-Code Button-Click Event will be a "Private" Sub, private Sub's are not shown on the Macro menu!

Like:

Private Sub CommandButton1_Click()
'Run from the Sheet Module for the Sheet that has the control on it!

'Any code you want here!
MsgBox "Test1!"
End Sub

For the control toolbox button on Sheet1.
 
Upvote 0
You can also do this by making the Excel Toolbar: "Tools - Macro" menu item Grayed-out and un-selectable from the menu!

Note: You must make it un-Gray on exit or it will stay that way!

Also, count the items down to "Macro" on your menu and change the Control number in the () below if needed for your system!

Private Sub Workbook_Open()
'ThisWorkbook code!

'"14" is the Excel Toolbar "Tools" menu item count down to "Macro"
'count each item including mouse-overed Gray or additional items!
Application.CommandBars("Tools").Controls(14).Enabled = False
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'ThisWorkbook code!

'"14" is the Excel Toolbar "Tools" menu item count down to "Macro"
'count each item including mouse-overed Gray or additional items!
Application.CommandBars("Tools").Controls(14).Enabled = True
End Sub
 
Upvote 0
Thanks Joe
That is brilliant . One more question on my computer I had to change the 14 to 11 will it me 11 on all my users computers?

Thanks again
Have a great weekend
L
 
Upvote 0
Its ok I check some other computers and yes they were also 11
thanks again

L
 
Upvote 0
Hi,
I think it depends on which version of Excel you are using. For me (Excel 2002) Macro in Tools is 14th Control.
 
Upvote 0
True it is version dependent.

It is also dependent on which menu catagory you are working with, like your list of recent files is dependent on the number you have set for this option to return.

Or, if you have the "Always Show Full Menus" option de-selected or not. In this case the count and or order can change even among the same versions.
 
Upvote 0
Were it me, I'd use Joe's first suggestion of making the Sub's PRIVATE. Why monkey with enabling/disabling the user's menu? Maybe he has a generic utility macro in his personal WB that he'd like to use and now you've impacted that for him. If you feel you must disable this (will this also disable the Alt+F8 hotkey???) then I'd use the FindControl method, passing in the ID # for that menu option. I have a couple of add-ins that I've written myself that alter the content of the Tools menu. Who's to say your user(s) haven't or won't have add-ins that alter their menu structure?
 
Upvote 0
Yes, Greg is correct:

Alt+F8 will still pull up the Run Macro list!

You can dissable this key combination with:

Application.OnKey "%{F8}", ""

and re-activate this key combination with:

Application.OnKey "%{F8}"


Once again as Greg has indicated, unless you take full control of the menu by first hiding any user modified toolbars and replacing them with generic default menus. You could run into problems!

I would make all my Subs "Private" and then PassWord protect the Project so my Modules are hidden!
 
Upvote 0

Forum statistics

Threads
1,216,033
Messages
6,128,427
Members
449,450
Latest member
gunars

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