Address Retrieval Macro

R

Rob F

Below is a macro I use to insert addresses directly from
my Outlook address book into a Word document (the macro is
in Word). It's not a macro I wrote myself, I hasten to add!

My only niggle is that when the address book dialog opens
it opens with our networked Global Address Book active. I
would prefer it to open with my "personal" Outlook Address
Book Contact list active.

I first posted this query in the Word VBA newsgroup, as
it's a Word Macro. Doug Robbins, a Word MVP, replied:
"The GetAddress method Returns an address from the default
address book. I think that changing the default address
book is probably more of an Outlook issue rather than a
Word issue. As a result, you may be more likely to get
the information that you need if you post to one of the
Outlook newsgroups" so I thought I'd post here too.

Incidentally, I don't want to change my address book
opening default from Global Address Book, as that's
handiest for me. Sorry if it makes things more
complicated :)

Can anyone suggest a change to the macro, please?

Cheers

Rob F

******

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

End Sub
 
S

Sue Mosher [MVP]

If you don't want to change the default, then you can't make this work the
way you want.
 
K

Ken Slovak - [MVP - Outlook]

That method will only retrieve an address from the default address
book.

Even CDO 1.21's Session.AddressBook method will start by showing the
default address book first. CDO 1.21 is also restricted in secure
versions of Outlook and is an optional installation with Outlook 2000
and later.

The only way I know of to specify which address book to use in an
AddressBook method is Redemption's MAPIUtils.AddressBook method in
conjunction with MAPIUtils.AddressBookFilter. See
www.dimastr.com/redemption for examples of Redemption code and
information about Redemption.
 

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