Need syntax for If user name in before save event

M

mikeburg

I am trying to execute code in BeforeSave in ThisWorkbook when the
user's name is Mike. I tried the following but it does not work

If Environ("UserName") = "Mike" then Msgbox Environ("UserName")

I also tried the following but it does not work either:

User = Environ("UserName")
If User = "Mike" Then MsgBox User

I must not be using the correct syntax. Can someone help? Thanks a
lot. mikeburg
 
C

Chip Pearson

What do you mean "does not work"? Are you sure the UserName is
actually 'Mike'. Note that Environ("UserName") returns the user's
network logon name, not the UserName listed in Tools, Options,
General.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"mikeburg"
message
news:[email protected]...
 
M

mikeburg

What I mean is that anything within the If statement does not execute.

Yes, I am sure that UserName is mike, because I can put the following
in the before save event & the message box displays the word Mike

Msgbox Environ("UserName")

Also, thanks for your comment about the log on name. I didn't realize
that. What would be the code to MsgBox the user name in Tools,
Options, General?

However, more importantly, how can I get the If statement to work?

If Environ("UserName") = "Mike" then Msgbox Environ("UserName")

Thanks for your replys. mikeburg
 
C

Chip Pearson

What would be the code to MsgBox the user name in Tools,
Options, General?

MsgBox Application.UserName
However, more importantly, how can I get the If statement to
work?

Your code should work. Are you sure capitalization is correct?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"mikeburg"
message
 
M

mikeburg

Thanks so very, very much. The login is set to mike when my if
statement contained "Mike". I don't know why sometimes I have trouble
with the simplest things.

Oh well, at least now I know the difference between the two users.

mikeburg
 

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

Top