VBA: IF / ELSE


Posted by Phil on June 21, 2001 8:34 AM

What i am trying to is - is make a macro so thatwhen pressed will ask the user to type in a password.

if that password is correct i want the macro to continue to run. if the password is incorrect i want it to show a msg say incorrect password.

I think it would just be a case of writing an if statement - if prompt value = cheese conitue else end if...

with the password being cheese

The main reason i amdoing this is because i have loads of users sharing the same workbook. And only what the managers to be able to use some of the macros.

Any1 got any suggestions..


Cheers

phil



Posted by Ben O. on June 21, 2001 9:07 AM

Seems pretty straightforward. Just put this code at the beginning of your macro. Or put an Application.Run("Your Macro") statement at the end of this macro:

Sub PasswordPrompt()
x = InputBox("Please enter your password", "Enter Password")
If x <> "cheese" Then
Exit Sub
End If

y = MsgBox("Correct", vbOKOnly)

End Sub

-Ben