|
Microsoft Office Application Development
|
|
Creating an addin from an Excel macro. Introduction 1 2 3 4 5 6 7 8 9 10 Conclusion Blocking Direct Access To Subs And FunctionsIn general, utilities are built using various functions and subroutines, each having specific tasks. Very often it is convenient (and even to be advised) to limit user access to just those functions and subroutines that enable the user to access the user interface or core functions of the utility. All other routines (those that do the internal "house-keeping" work and those performing sub-tasks) should be kept hidden from the users view. By default, all subs are visible in the Macro dialog (see figure below)
It is not a good idea when all subs in the utility are shown to the user. Some subs will very likely only work when called at the appropriate places in other subs or functions and thus exposing them to the user may cause serious trouble. Subroutines that do housekeeping work for the utility do not belong in this list so should be hidden from view. Arguably one could remove all subroutines from the list, since it is better to grant access to the methods and functions through menu's and toolbars anyway. Below are three possible methods to control what is shown in the above dialog and what isn't. Make the module privateBy adding the text: Option Private Module at the top of a module, all subs in that module are removed from the macro list. They can still be started from that dialog however, by simply typing their name and clicking Run. Make the sub PrivatePrivate Sub
InvisibleSub() The disadvantage of using this method is that the sub is now inaccessible from outside the module that contains it. This is no problem when the sub will only be called from within the module. Use an optional argumentAnother way to hide subs from view is by giving them an optional argument: Sub InvisibleSub(Optional bDummy As Boolean) This subroutine doesn't need an argument when one wants to call it: InvisibleSub Using the argument would of course yield the same result, provided the argument is not used inside the subroutine.
| ||||||||||||||
|
Use the contact page to issue
questions or comments about this website. |