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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,215,330
Messages
6,124,307
Members
449,151
Latest member
JOOJ

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