My task has been to create a secure (Windows version) Excel workbook that uses macros to validate whether a user has permission to view the contents. In Excel 2010 for Windows, I use the Environ("username")
function to accomplish this.
The problem I'm running into is that some users in the organization use a Mac to do their daily work, and Environ
does not work with OSX.
Does anyone know of an alternate way to find the username of a Mac? I've looked online but all I can find is how to find the unique identifier of the computer, not the username.
Is what I'm attempting to do even possible with Mac?
Any information is appreciated!
Environ("username") is the user name which you log into Windows with. Application.UserName is the user name which is set by the user when they run the program for the first time or whatever it was if you go to TOOLS > OPTIONS > GENERAL and set it under User Name.
We have created “GetComputerUserName” macro to find the computer and user name. We can run the macro by clicking “Submit” button. Macro will extract computer name in cell C10 and user name in cell C11. Environ function returns the string value associated with environment variable of the operating system.
You can use AppleScript to return the Username and run that from VBA.
The following function should do the trick.
Function GetUserNameMac() As String
Dim sMyScript As String
sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"
GetUserNameMac = MacScript(sMyScript)
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With