简体   繁体   中英

Is there a way to hide macros in Excel?

I just finished some VBA and I was wondering if there is a way to hide certain macros on Excel.

I need the user to run a certain macro and only that one, but it shows all the sub macros in Excel. I want to hide the unnecessary macros from the user so that way the user doesn't accidentally click on the wrong one.

You can also do this by placing the macros you want to hide in a separate module and using Option Private Module at the top of the module before the code. The macros will still be available to your project but will not appear in the Macros seen by the user when he clicks the Macros button.

您可以在功能区中创建一个按钮来运行宏,也可以在VBA编辑器中的每个“Sub”之前添加“Private”,而不希望用户轻松访问。

To subjectively 'hide' certain sub procedures (ie 'macros') from the (Alt+F8) Developer, Macros dialog use an optional non-variant parameter that means nothing.

Sub meh(Optional w As Worksheet)
    Debug.Print "hello world"
End Sub

The meh macro will not show up in the list of macros to run. If you dim the parameter as variant it will show in the list. This is likely due to a optional variant parameter being able to use the IsMissing function. It will also not be able to be run from the VBE with F5 or stepped through with F8.

The test sub procedure will run the code correctly.

Sub test()
    meh
End Sub

Sub meh(Optional w As Worksheet)
    Debug.Print "hello world"
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM