Sub Not Working

G

Guest

Here's the code I'm working with...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If Application.UserName <> rcj Then

Cancel = True
MsgBox "Sorry, But You Don't Have Permission To Save This File",
vbExclamation, "Invalid Permission"

End If

MsgBox Application.UserName

End Sub

I get the error and it doesn't save, but if I use ... Application.UserName =
rcj Then I get to save but that's backwards I want it to elvaluate what the
username is and if it's not my username than it cancels the save and lets the
user know. Why is it working backwards?

Thanks,
Rob
 
J

Jim Cone

If Application.UserName <> "rcj" Then
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Rob" <[email protected]>
wrote in message
Here's the code I'm working with...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.UserName <> rcj Then
Cancel = True
MsgBox "Sorry, But You Don't Have Permission To Save This File",
vbExclamation, "Invalid Permission"
End If
MsgBox Application.UserName
End Sub

I get the error and it doesn't save, but if I use ... Application.UserName =
rcj Then I get to save but that's backwards I want it to elvaluate what the
username is and if it's not my username than it cancels the save and lets the
user know. Why is it working backwards?
Thanks,
Rob
 
G

Guest

HA! I feel sooo silly.

Thanks.

What if i wanted to add another username to ba allowed to save (i.e. pbcj)?
I tried below but I get a type mismatch runtime error 13.

If Application.UserName <> "rcj" Or "pbcj" Then


Rob
 
T

Tim Marsh

If Application.UserName <> "rcj" Or Application.UserName <> "pbcj" Then

hth,

tim
 
G

Guest

Thanks Tim, But when I incorporate that string it gives be the permission
error. If I remove the additional user from it the it works again. it seems
like I can only have one user.

Any other ideas?

Thanks tons,
Rob
 
T

Tom Ogilvy

there is a logic error in the statement. Try

If Application.UserName <> "rcj" and Application.UserName <> "pbcj" Then


One statement will always be false, so you can't use OR.
 

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

Similar Threads


Top