Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Running Code-Alt F8 (XL97; SR2)

    One can restrict access to code in various modules by protecting them with a password. Does anyone know how to prevent someone from pressing the ALT F8 keys, to view/run the various subroutines?

    Thanks,
    John

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    John,

    If you put this sub in a global template, or even the document/template that you want to protect, then if your user presses Alt+F8 or goes to Tools|Macros|Macros... all they will get is a message box that says disabled.

    Sub ToolsMacro()
    MsgBox "Disabled"
    End Sub

    Basically what this does is "hijack" the ToolsMacro built-in Word Command.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    Simplicity at it's best.

    Thanks,
    John

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    John,

    You might also want to consider the following (from <post#=149810>post 149810</post#> on the Word board) - it may be less intrusive to keep the user from seeing the macros in the first place, rather than taking away their ability to use that dialog:

    <hr>In some (many) cases it may be more appropriate to keep the code in an attached template rather than a global template.

    Although you can't grey out the Edit button for macros that are in an attached template, you can keep them appearing in the list altogther. A few ways to do that:

    <UL><LI>Make them into Subs that take arguments (or Functions for that matter).
    <LI>Make them Private rather than Public Subs (only callable by other Subs in the same Module)
    <LI>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.[/list]<hr>
    Gary

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    Gary,

    Thank you for your suggestion. I went with the Option Private Module.

    John

  6. #6
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    Gary,

    When I placed "Option Private Module" as the first piece of code in a module and try to run code such as:
    Lastuser = Application.Username

    I receive the following error message: Compile Error-Can't find project or library.

    Can you provide further information on this error message? I tried looking for a resolution in references but was unable to figure it out.

    Thanks,
    John

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code-Alt F8 (XL97; SR2)

    Persistance pays off. There was a MISSING object in the reference. Once I established the proper reference it worked just fine.

    Thanks once again,
    John

Posting Permissions

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