VBA: Problems with Environ("Username")?

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I have recently started using Environ("Username") quite a bit. I use it to track who's using my workbook, or track issues certain users may be having, and also to make a few of my userform functions a bit more user friendly. I've been having these strange issues with my workbook that I had not previously been able to really track down or fix, and only recently tied these issues to my uses with the Environ commands I was using. So, I decided to go back to the basics and remove all of my code that I was using the Environ command, except for error tracking purposes. Well, I came into work this morning and was going over any of the issues that may have popped up since last week, and noticed that on one of the errors it tracked it had recorded the wrong username for the time stamp that it had recorded. There was another one where it didn't record a username at all. So, something dawned on me, and I was able to come up with a theory as to why I was having an issue when using the Environ command. I think what is going on is that every once in a while a user forgets to log off of the computer, so it automatically locks, and then the next user logs in. So then there are 2 people logged into the same computer (1 active and 1 inactive).

- Would this cause confusion in my code when Excel tries to determine what Environ("Username") to use for a certain command?
- Is there a way to force excel to use the active username and ignore the inactive one?
- Any thoughts or suggestions for me?
- Is the Environ command known to be a bit finicky?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this:

Code:
Function CurrentUser()
Set objNetwork = CreateObject("Wscript.Network")
CurrentUser = objNetwork.username
End Function
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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