View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed Lisay Ed Lisay is offline
external usenet poster
 
Posts: 5
Default Hiding Macro from View

John,

This should fit your need.
I have several VBA applications that I not only want to
protect the code, but also need to prevent the User from
running a macro out of sequence (They click a button to
run them).
1. First, protect all the macros with password.
In the workbook load event, set a variable to a value.
For example:
okToRun = False
2. Then in each marco, add code to check the value of a
variable.
if example:
If okToRun = False Then
MsgBox "You are not authorized to run this macro." &
vbCrLf & "Contact for additional
information.", vbExclamation, "Security Warning"
Exit Sub
Else: End If
3. Then in the event that allows the User to run the
macro (clicking the command button in my example), set
the variable to True:
okToRun = True

Show, the macros are still visible, but can't be run
unless the button is clicked.
Hope that helps. Email me if you have any questions.

Ed