Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel/VBA Environ("username") error

Tags:

excel

vba

I have a spreadsheet that contains a range of model inputs that get loaded into a SQL Server database. Part of this process involves building an audit trail of who updated what and when - I record the user and machine name as well as timestamp.

Within my VBA code, I have the following:

user = VBA.environ$("username")

This is running on a Win7 machine, with Office 2013.

When I run the code, it all works fine, but when someone in production runs it (on the same machine, but they are logged in, not me), it falls over on the line above. I have used variations of the above (user = environ("username"), user = environ$("username")) but always with the same outcome - it works for me, but not for others.

Does anyone have any thoughts on how to fix this?

like image 439
John Avatar asked Jan 05 '23 07:01

John


1 Answers

Here you are:

Sub Test()
    With CreateObject("WScript.Network")
        Debug.Print .UserName
        Debug.Print .ComputerName
        Debug.Print .UserDomain
    End With
End Sub
like image 129
omegastripes Avatar answered Jan 15 '23 23:01

omegastripes