VBA: Hide a Macro

Automate Excel

VBA: Hide a Macro

If you would like to hide a macro from appearing as an option in the Macro dialog box, it can be done by declaring it as Private.

The following are two macros, only the first one will appear to the user, the second is declared as Private so it will not be visible.

Sub Macro1()
     Call Macro2
End Sub

Private Sub Macro2()
     MsgBox "You can only see Macro1"
End Sub

hidemacro

Note: This only works if both Macros are in the same Module.

3 Responses

  1. fxp Says:

    You can also hide macros that are attached to worksheet objects, too. After you assign a macro to say a button object go back to the module and declare it private. This will hide the macro, but it will still be linked to the button.

  2. Jon Peltier Says:

    You can also hide a macro by putting an optional argument in its declaration:

    Sub Macro1()
    Macro2
    End Sub

    Private Sub Macro2(Optional bTest As Boolean)
    MsgBox “You can only see Macro1″
    End Sub

    Since the argument is optional, the procedure won’t complain if you don’t pass it.

    - Jon

  3. Oscar L Says:

    Hey this one worked great!!

    Thank you much.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.