cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB script to read user first name, last name and contact number from outlook ?

VB script to read Current user First name, last name and contact number from outlook ?
(2) Replies
Require a script which will extract Current user name (first name and last name) and contact number From the Microsoft Outlook.
Got the Script 😉
Const PR_GIVEN_NAME = &H3a06001e
Const PR_INITIALS = &H3a0a001e
Const PR_SURNAME = &H3a11001e
Const PR_7BIT_DISPLAY_NAME = &H39ff001e
Const PR_STREET_ADDRESS = &H3a29001e
Const PR_LOCALITY = &H3a27001e
Const PR_STATE_OR_PROVINCE = &H3a28001e
Const PR_POSTAL_CODE = &H3a2a001e
Const PR_COUNTRY = &H3a26001e
Const PR_TITLE = &H3a17001e
Const PR_COMPANY_NAME = &H3a16001e
Const PR_DEPARTMENT_NAME = &H3a18001e
Const PR_OFFICE_LOCATION = &H3a19001e
Const PR_ASSISTANT = &H3a30001e
Const PR_BUSINESS_TELEPHONE_NUMBER = &H3a08001e


set Application = GetObject("","Outlook.application")
' If there was an error, Outlook probably wasn't Open, so open it now
if err.number <> 0 then
err.clear
set Application = CreateObject("Outlook.application")
if err.number <> 0 then
msgbox "Problem trying to create Outlook object, unable to continue"
wscript.quit
end if
end if

set olemSession = Application.CreateObject("MAPI.Session")
ReturnStatus = olemSession.Logon( Application.GetNameSpace("MAPI").CurrentUser, "", False, False, 0 )

Set myself = olemSession.CurrentUser

msgbox myself.Fields.Item(PR_GIVEN_NAME) & " " & myself.Fields.Item(PR_SURNAME) & " " & myself.Fields.Item(PR_BUSINESS_TELEPHONE_NUMBER)