I’ve discovered that private functions are still available from the worksheet. They’re hidden, but if the user types their name, they will be called. Why? Is it supposed to work this way? Is there a way to completely block user defined functions from being used outside of the VBA project? I’ve tried declaring functions with the
Private keyword, or placing
Option Private Module at the top of my module. Thanks in advance.
Option Private Module, simply hides the UDF from the Function Wizard. This option lets you hide modules from external users and makes it easier to see your exposed function calls. You can still use them from the worksheet if you know the function’s name. That’s how it works.
However if you try to use that Private Function from anywhere else, for example Worksheet_Change event, you will not be able to. And if they are declared as “Public” with “Option Private Module” then they can be accessed.
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.
Regarding your question
Is there a way to completely block user defined functions from being used outside of the VBA project?
There are 2 ways that I can think of
1) Protecting your VBA Project so that the user doesn’t know the name of the function.
2) Creating an Add-In