Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hiding Macros from users (English Word 2003)

    I have a template in the Word startup folder that contains lots of macros assigned to a number of keys. I'd like to hide all these macros from the user as they can be seen from the Tools:Macro:Macros. I can hide them by making a macro "Private" but if I do that Word then can't find that macro in the routine I use to assign them to the keys.

    I have used a number of modules to group similar macros together.

    Any ideas please....

    Dennis

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Hiding Macros from users (English Word 2003)

    I don't believe you can do this, though I am by no means a Word expert, so hopefully someone will prove me wrong. You can also hide the macros from the Macros dialog by adding an optional typed parameter but this hides them from the menu Customize dialog too and seems to prevent <code>Application.KeyBindings.Add</code> from working. (is that the code you are using?)
    As a matter of interest, why do you want to hide them, given that you are allowing acces to run them anyway?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hiding Macros from users (English Word 2003)

    I have come to the same conclusion - methods that remove a macro from the Macros dialog also disable the possibility to assign a shortcut key.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Hiding Macros from users (English Word 2003)

    You want to prevent users from running them through other means? That seems a bit difficult.

    In theory, you should be able to ascertain the control used to invoke a macro, but when I've tried this in the past, I never quite worked out how to do it.

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Hiding Macros from users (English Word 2003)

    I found it was possible to create a macro that is hidden but could be run from a toolbar button by...
    1. Create the Sub
    2. Create the toolbar button customisation to run the Sub
    3. Change the Sub to a Function

    Whilst this worked, the same process did not allow me to customise a keyboard command to run the macro.

    Perhaps a workaround could be arrived at whereby all of your subs are changed to functions and you show just one sub which can call any of the functions but only if a keyboard modifier is held down. This gives the users the impression that there are no macros (apart from one sub which does nothing) but you could use it as your anchor for all the keyboard commands.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    Thanks for all the replies, it's nice to know that it's not me!

    Since my template has a lot of macros in it that get bound to various key combinations I just wanted to remove them from the Macro list as there is no need to run them manually. It would also then stop the "clutter" that they make in the list so that any personal macros the staff member has created can easily be seen. I just like things tidy!

    Thanks
    Dennis.

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    "user" and "manually" in this thread ought to be synonymous.
    If you have code that is to be accessed directly by the user, Word's interface includes:
    (a) Menu (Tools, Macro, Macros) and
    ([img]/forums/images/smilies/cool.gif[/img] Keyboard assignments (shortcut keys) and
    Mouse assignments (toolbar buttons).
    This is how end-users talk to programs. Your program included.

    Macros are procedures that can be assigned/accessed in this way; macros are your user interface. Anything else ought not be a macro.

    Try this:
    Make a list of those procedures which are to be invoked directly by your user. These are your macros. Make them "Public Sub"s with no parameters.
    Make every other procedure a public function with a parameter, returning a result, or both. (I find it hard toi think of a reason for a function NOT to be returning a value).

    You will find that your users have access to what you want them to have, and do not have access to what you don't want them to have.
    Your users will be provided with the choice to invoke your code via menu, keyboard shortcut or mouse-click, as is their right.
    Your public functions will be available to you, and any other developers on your system, as a library of procedures to sped up your application dveelopment.

    I know that in VBA users can invoke public functions that have no parameters. I've found it much easier to make every procedure a Function except for those procedures that are to be invoked by the end-user.

    More complex user interfaces are prepared through the user of GUI forms with event processing.

  8. #8
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    I did a quick test but it didn't work, I'm afraid. The Keybinding routine fell over at the line where I had changes the Sub to a Function.

    I like the idea though. I never thought of using a Function instead of a Sub for things that don't need a return. Just thinking about it though, I think most of Windows kernel calls are Functions that are often used as simple Subroutines.

    I'll do some more tests as soon as I can. It may also have something to do with the way I've separated the macros into different Modules that may be causing a problem.

    TTFN
    Dennis

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    > fell over at the line where I had changes the Sub to a Function.

    I can be a bit harsh at times. [gentler] Carry on with your vest efforts in your current project, but in your next project try the suggested method.

    I generally have a very good idea of the user interface; the user says "I want to do (a), ([img]/forums/images/smilies/cool.gif[/img] and ". That tells me I need three macros, "MacroA", "MacroB", and "MacroC".
    That's what the user has asked for, it's what I've proposed, and it's what I'm being paid for.
    With those three macros in place as parameter-less "Public Sub"s, every procedure I write from then on will be a Public Function, with parameters and a result, but never with no parameters and no result.
    It makes my life very easy, and cannot confusauser.[/gentler]

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Hiding Macros from users (English Word 2003)

    <hr>I find it hard toi think of a reason for a function NOT to be returning a value<hr>
    there are few reasons (which is not to say none) to write a function that returns nothing. In fact, there are those who would argue that everything should be a function unless it needs to be called from a menu button or a key combination. That way you can return as many parameters as necessary (just pass them ByRef) and always return at least a True/False value to indicate whether the routine failed or not. However, as with all things, the realities of life may interfere with the theories of best practice! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    > those who would argue that everything should be a function unless it needs to be called from a menu
    Oh, you've met me then? (grin!)
    Regardless of the rights-and-wrongs, I find this approach serves me well in clarity of design.
    Of course, it has also turned every one of my applications into a cornucopia of useful utility procedures! In some cases, into powerful engines.

  12. #12
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Hiding Macros from users (English Word 2003)

    I confess I oscillate between the thinking that everything needs to return some sort of success value, and that some things should just work; if they don't something major has gone wrong and should be dealt with accordingly - i.e. either everything returns False if it doesn't work or something blows up. Sometimes I like the latter as it lets you know that something really weird has happened!
    Regards,
    Rory

    Microsoft MVP - Excel

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    [lunch break] I did an analysis on my main library (UW.DOT) which holds 706 procedures.
    36% are Functions with No results!
    04% are Subs (with no results, natch)
    60% are Functions with results.[/lunch break]

  14. #14
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Hiding Macros from users (English Word 2003)

    Hi Dennis,

    Put an "Option Private Module" declaration at the top of any code Module housing subs you don't want the user to see in the Macros list. These subs will be callable by any other sub in the same project, but not by any sub in any other project.

    Another solution is to add an optional argument to the parameter list for each sub you want to hide. This works because macros that have arguments (even if they're public macros) don't show in the 'run macro' list. The macro is still available to those who know it's there (or just called from a button). If the code has to remain Public (because it's used in multiple modules) but you don't want the users to be able to see it in the list of macros (from the macro recorder) or to run it, use something like:

    Sub HiddenMacro(optional NoVal as Boolean = True)
    ' your code here
    End Sub

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  15. #15
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding Macros from users (English Word 2003)

    Sorry, still doesn't work. It always falls over in the module that has all the KeyBinding commands. I'm going to try re-writing the code to put the some of the routines I want hidden in the same module as the KeyBinding routines to see if that works.

    Thanks to everyone who has offered help so far. As soon as my latest project is out of the way I'm going make to this problem. There MUST be a solution somewhere. If I every find it I'll post the result.

    TTFN
    Dennis

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •