Outlook First Name

meboe

New Member
Joined
Mar 11, 2003
Messages
22
Currently I am using the login id (username) to personalize an Excel Macro.

Application.UserName + " --- Please Stand By while the page layout is formatted."

Can I instead call up the User's first Name, say from Outlook?

Thanks, Greg
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
meboe said:
Currently I am using the login id (username) to personalize an Excel Macro.

Application.UserName + " --- Please Stand By while the page layout is formatted."

Can I instead call up the User's first Name, say from Outlook?

Thanks, Greg

Greg - Application.Username is not a login user name rather it is the user of Excel set up in Tools - Options. Quite often this is blank unless users have been told to enter themseleves in there.

Environ("Username") extracts the NT login.

As for your Outlook request - the below extracts a specific address list and extracts the full name of the user on the basis of a look up using the NT login. In short it extracts the full details from the address book and then trims it to return the login only, then in an adjacent column it returns the full name - you can then run a vlookup in VBA of the Environ("Username") to determine the full name of the user....if you wanted to you could trip the Fullname to a forename using an InStr search. This requires the Outlook Object Library to be referenced in VBA.

Sub Standard()

Dim objOutlook As Outlook.Application
Dim objAddressList As Outlook.AddressList
Dim objAddressEntry As Outlook.AddressEntry

'Setup connection to Outlook application
Set objOutlook = CreateObject("Outlook.Application")
Set objAddressList = objOutlook.Session.AddressLists("Global Address List")

Application.ScreenUpdating = False

Sheets("OUTLOOK").Visible = True
Sheets("OUTLOOK").Select

'Clear existing list
Sheets("OUTLOOK").Range("A:B").Clear

n = 0

'Step through each entry in List and return full address to A
'Step through each entry in List and return name to B
For Each objAddressEntry In objAddressList.AddressEntries
If objAddressEntry.Address <> "" Then
n = n + 1
Sheets("OUTLOOK").Cells(n, 1) = objAddressEntry.Address
Sheets("OUTLOOK").Cells(n, 2) = objAddressEntry.Name
End If
Next objAddressEntry

'Reduce Full Address to Login
n = 1
x = InStrRev(Cells(n, 1), "=")

Do Until Cells(n, 1) = ""
Cells(n, 1) = Right(Cells(n, 1), (Len(Cells(n, 1)) - x))
n = n + 1
Loop

Cuser = Environ("Username")
CName = Application.WorksheetFunction.VLookup(Cuser, Sheets("OUTLOOK").Range("A:B"), 2, 0)

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,706
Messages
6,161,406
Members
451,702
Latest member
Kc3475

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