Application.Username and environ("Username")

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,

Application.Username and environ("Username") gives different values in excel 2007
But it does not in 2003. Both gives environ("Username").value.
Please help me how to figure this out in excel 2003.

Thanks.
Pedie;)
 
I'm glad that we could help.

Bob, I would not do it that way as that errors at runtime. You can show it this way though.
Code:
Sub Test_Environ()
  Dim tf As Boolean
  MsgBox Environ("username")
  tf = Environ("username") = "Silly Name"
  MsgBox Environ("username"), , tf
End Sub

I do use API's for getting and setting environment variables sometimes. FSO methods are easy to use too. I once wrote a kb entry for vbaexpress.com to illustrate the various methods but it was not posted. I can think of about 4 ways or more to get and set them. There are some differences as you know.
 
Last edited:
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You can add a username in this macros dialog that it shows and set a value. If you close Excel and then open, Environ("username") will return the new value.

Code:
Private Sub ChangeEnvs()
  Dim rc As Long
  'Shell "cmd /c RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3", vbNormalFocus
  Shell "Control.exe sysdm.cpl,,3", vbNormalFocus
  Do Until FindWindow(vbNullString, "System Properties") <> 0
  Loop
  Application.SendKeys "n", True
End Sub

Turn UAC off if you have Vista+ for SendKeys() to work. Such a minor thing though, you can just press 2 for testing purposes.
 
Upvote 0

Forum statistics

Threads
1,225,759
Messages
6,186,863
Members
453,380
Latest member
ShaeJ73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top