View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Locking Macros from being edited, but not viewed.

The idea is to lock a macro so it cannot be changed, but can still be
viewed. Some of the higher-ups don't appreciate my protection.
Thanks,
-Pistolade-


Unfortunately Excel's VBProject protection scheme isn't that granular.
If users can see it then they can also modify it!

What I do for myself is my projects disable any/all ways to access the
VBE and build a mechanism into them that enables me 'developer' access
to the VBE based on a specific file being located in the same path as
the Excel file. This file contains encrypted project-specific info so
it can't be copied/used with other projects. My projects use this to
configure UI settings at startup so they know which built-in menus and
keyboard shortcuts to disable for normal users.

This might be a more complex solution than you're looking for, though!

Another approach is to 'hook' all UI actions that target access to the
VBE to require a username:password login to enable. As stated earlier,
though, this will allow viewing/modifying unlocked projects.

Finally, you could implement a mechanism that prints or displays your
code based on user login. This involves getting the 'Current User' via
something like...

If InStr(1, sAllowedUsers, Environ("username")) 0 Then
'print or display the code
End If

...which you can manage via a simple button (or menuitem if your project
creates its own menus/toolbar).

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion