In Excel VBA (2003), I\'ve noticed that any Public or Friend Sub method in either a module or ThisWorkbook that
Just a small addendum to Jason Z's answer: methods hidden by Option Private Module
are still visible if you use Application.Run()
to invoke the method.
One solution is to give the method an Optional
argument.
Public Sub myPublicSub(Optional dummy_var As Integer)
...
End Sub
My methods have already been listed however, ChrisB made the following statement:
Perhaps we should all have Option Private Module at the tops of our code modules as a rule – except where the module contains procedures called by buttons
Even Private routines can be called from a button if the Macro is assigned to the button before making it private.
Add the following to the top of your module:
Option Private Module
From MSDN:
When a module contains Option Private Module, the public parts, for example, variables, objects, and user-defined types declared at module level, are still available within the project containing the module, but they are not available to other applications or projects.
Also worth noting a side effect of both Option Private Module and adding Optional Params is that the Sub will no longer work as a target of a shortcut keybinding.
Restated: If you have a keybinding to set a keyboard shortcut to launch a Macro. That Macro cannot be hidden. Otherwise the keybinding will not work.