Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need syntax for If user name in before save event


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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=508723

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Need syntax for If user name in before save event

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"
wrote in
message
...

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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile:
http://www.excelforum.com/member.php...o&userid=24581
View this thread:
http://www.excelforum.com/showthread...hreadid=508723



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Need syntax for If user name in before save event

. . . not the UserName listed in Tools, Options,
General.



which is returned with

application.UserName

In case you need to know.
--
Regards,
Tom Ogilvy


"Chip Pearson" wrote in message
...
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"
wrote in
message
...

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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile:
http://www.excelforum.com/member.php...o&userid=24581
View this thread:
http://www.excelforum.com/showthread...hreadid=508723





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need syntax for If user name in before save event


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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=508723

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Need syntax for If user name in before save event

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"
wrote in
message
...

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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile:
http://www.excelforum.com/member.php...o&userid=24581
View this thread:
http://www.excelforum.com/showthread...hreadid=508723





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need syntax for If user name in before save event


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


--
mikeburg
------------------------------------------------------------------------
mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
View this thread: http://www.excelforum.com/showthread...hreadid=508723

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Defined Function Syntax Ankur Excel Worksheet Functions 2 January 3rd 07 01:41 PM
Syntax of If statement in before print event mikeburg[_24_] Excel Programming 3 September 14th 05 03:18 PM
user form-on open event? keydown event? FSt1[_3_] Excel Programming 2 August 5th 04 02:26 PM
Save Event - Determine if called by code or user David Sedberry Excel Programming 0 October 2nd 03 04:56 PM
need help with syntax of a Workbook Event Paul Simon[_2_] Excel Programming 3 July 30th 03 03:43 AM


All times are GMT +1. The time now is 06:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"