require password each time a macro is executed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Workbook contains serveral worksheets with a number of macros. If the wrong
macro is executed for a given worksheet it will ruin the integrity of the
worksheet.
How do I avoid this problem other than using passwords.
 
Workbook contains serveral worksheets with a number of macros. If th
wrong
macro is executed for a given worksheet it will ruin the integrity o
the
worksheet.
How do I avoid this problem other than using passwords.

Hi Marty
If you know which macro should by run in which sheet, then code it s
it checks the sheet before running. Post back if you requir
help.........in coding this ... but give details
 
Include a line in your code which checks that the required worksheet is
selected before the macro continues.
 
Thanks Ivan,
I understand but is this an if statement and how do you write it?
Marty
 
Thanks Bigwheel,
I am rather new at this and understand your answere but have no idea how to
write it . Can you help?
Thanks again
Marty
 
If you can pick out something unique for that type of worksheet, then you can
test that to see if it's there.

For instance, if you have headers in A1:X1 and A1 always contains the text:
"Order Number"

you could put this at the top of your code:

sub testme()
if activesheet.range("a1").value <> "Order Number" then
msgbox "Not on this sheet"
exit sub
end if
'your other code here
end sub

The question now becomes: Can you find something unique?
 
Sub Macro1()

if lcase(Activesheet.Name) <> "sheet1" then
msgbox "Sheet2 must be active to run this macro"
exit sub
End if

' existing code that works on the active sheet.

End Sub

Marty said:
Thanks Ivan,
I understand but is this an if statement and how do you write it?
Marty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top