environ username vs. application username

J

jatman

i am using the following codes to obtain a user name:

Function ThisUser()
ThisUser = Environ("UserName")
End Function
Function MyName()
MyName = Application.UserName
End Function

both work, ThisUser returns my login id (ex. jat) and MyName returns my name
that i have entered in Excel's Personalization area (ex. jat man)

What i would like is to get the MyName to be retrieved from my actual
profile. When i go to Start, my name shows at the top (first last name), and
that is set up when my profile is created. How do i retrieve this in a macro?

jat
 
J

Jacob Skaria

Dear

Try the below and feedback...

Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
MsgBox objUser.displayName

If this post helps click Yes
 
J

jatman

i put the code provided in the Private Sub Workbook_Open event with the rest
of the open events...

Error message received is:
Run-time error '-2147023541 (8007054b)':
Automation error
The specified domain either does not exist or could not be contacted.

i press Debug, and the macro opens with the following line highlighted:
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

jat
 
J

jatman

I added the code to the Workbook Open events. when the workbook is opened, i
get the following error:

Run-time error '-2147023541 (8007054b))':
Automation error
The specified domain either does not exist or could not be contacted.

when i press the debug button, i the code is displayed with the following
highlighted:
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

jat
 
J

Jacob Skaria

This works only if you are logged in to a network domain.

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top