Outlook Address

D

David L.

Does anyone have a simple macro that does a lookup in Outlook contacts for a
specific name and copy the information into variables?
 
D

David L.

Thanks, but I'm really looking for something *simple* that I can assign each
part of the address & phone number to individual variables.

For example:

myAddress = <address info>
myCity = <city info>
myPhone = <phone info>
myFax = <fax info>

Thanks, David
 
D

David Sisson

I searched through Google "getaddress" and found this. Look at the end
of the sub for your answer.

Public Sub InsertAddressFromOutlook()
Dim strCode As String, strAddress As String
Dim iDoubleCR As Integer


'Set up the formatting codes in strCode
strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & _
"<PR_TITLE>" & vbCr & _
"<PR_COMPANY_NAME>" & vbCr & _
"<PR_POSTAL_ADDRESS>" & vbCr


'Display the 'Select Name' dialog, which lets the user Choose
'a name from their Outlook address book
strAddress = Application.GetAddress(AddressProperties:=strCode, _
UseAutoText:=False, DisplaySelectDialog:=1, _
RecentAddressesChoice:=True, UpdateRecentAddresses:=True)
'If user cancelled out of 'Select Name' dialog, quit
If strAddress = "" Then Exit Sub


'Eliminate blank paragraphs by looking for two carriage returns in
a row
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Do While iDoubleCR <> 0
strAddress = Left(strAddress, iDoubleCR - 1) & _
Mid(strAddress, iDoubleCR + 1)
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Loop


'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
'Selection.Range.Text = strAddress

'Here's the variable assignment.
ContactArray = Split(strAddress, Chr$(13))

CntName = ContactArray(0)
CntCompany = ContactArray(1)
CntStreet = ContactArray(2)
CntStreet2 = ContactArray(3)
CntCityState = ContactArray(4)

End Sub

You can use the ContactArray without reassigning it to other vaiables,
but it makes reading the code easier.

Hope this helps.
 

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