Word 2007 AddressLayout

E

Estimator

In Word 2007 I have modified "AddressLayout" as shown below. When I insert an
Outlook Contact address in a Word document everything prints correctly with
the exception that the email address is missing.
{<PR_DISPLAY_NAME>}
{<PR_TITLE>}
{<PR_COMPANY_NAME>}
{<PR_STREET_ADDRESS>}
{<PR_LOCALITY>}, {<PR_STATE_OR_PROVINCE>} {<PR_POSTAL_CODE>}
Phone: {<PR_OFFICE_TELEPHONE_NUMBER>}
Fax: {<PR_BUSINESS_FAX_NUMBER>}
Cell: {<PR_CELLULAR_TELEPHONE_NUMBER>}
Email: {<PR_EMAIL_ADDRESS>}
 
G

Graham Mayor

I have tested this and I agree it doesn't work. It may be concerned with the
way that the AddressLayout autotext works in Word 2007, however

Public Sub InsertFromOutlook()
Dim strName As String
'Set up the formatting codes in strCode
strName = "<PR_EMAIL_ADDRESS>"
'Let the user choose the name in Outlook
strName = Application.GetAddress("", strName, _
False, 1, , , True, True)
If strName = "" Then
MsgBox "User cancelled or no name listed", , "Cancel"
Exit Sub
End If
Selection.TypeText strName
End Sub

inserts the e-mail address, so it should be simple enough to modify the
macro at http://www.gmayor.com/Macrobutton.htm to insert the address details
in any layout you prefer.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Further to my last:

Public Sub InsertAddressFromOutlookA()
Dim strTitle As String
Dim strJobTitle As String
Dim strForeName As String
Dim strSurname As String
Dim strCompany As String
Dim strAddress As String
Dim strCountry As String
Dim strPhone As String
Dim strFax As String
Dim strCell As String
Dim strEmail As String
Dim strFinal As String

'Set up the formatting codes in strCode
strTitle = "{<PR_DISPLAY_NAME_PREFIX> }"
strJobTitle = "<PR_TITLE>"
strForeName = "{<PR_GIVEN_NAME> }"
strSurname = "<PR_SURNAME>"
strCompany = "<PR_COMPANY_NAME>"
strAddress = "<PR_POSTAL_ADDRESS>"
strCountry = "<PR_COUNTRY>"
strPhone = "<PR_OFFICE_TELEPHONE_NUMBER>"
strFax = "<PR_BUSINESS_FAX_NUMBER>"
strCell = "<PR_CELLULAR_TELEPHONE_NUMBER>"
strEmail = "<PR_EMAIL_ADDRESS>"

'Let the user choose the name in Outlook
On Error GoTo UserCancelled:
strAddress = Application.GetAddress("", strAddress, _
False, 1, , , True, True)
If strAddress = "" Then
MsgBox "User cancelled or no address listed", , "Cancel"
Exit Sub
End If
strTitle = Application.GetAddress("", strTitle, _
False, 2, , , True, True)
strForeName = Application.GetAddress("", strForeName, _
False, 2, , , True, True)
strSurname = Application.GetAddress("", strSurname, _
False, 2, , , True, True)
strCompany = Application.GetAddress("", strCompany, _
False, 2, , , True, True)
strJobTitle = Application.GetAddress("", strJobTitle, _
False, 2, , , True, True)
strCountry = Application.GetAddress("", strCountry, _
False, 2, , , True, True)
strPhone = Application.GetAddress("", strPhone, _
False, 2, , , True, True)
strFax = Application.GetAddress("", strFax, _
False, 2, , , True, True)
strCell = Application.GetAddress("", strCell, _
False, 2, , , True, True)
strEmail = Application.GetAddress("", strEmail, _
False, 2, , , True, True)

strFinal = strTitle & Left(strForeName, 1) & " " & strSurname & vbCr

If strCompany <> "" Then
strFinal = strFinal & strCompany & vbCr
If strJobTitle <> "" Then
strFinal = strFinal = strFinal & strJobTitle & vbCr
End If
End If

If InStr(strCountry, "United States") Then
strAddress = Left(strAddress, Len(strAddress) - 25)
End If
With Selection ' type in the name string _
using the Inside Address paragraph style
.Style = ActiveDocument.Styles("Normal")
.TypeText Text:=strFinal
.TypeText Text:=strAddress
.TypeParagraph
If strPhone <> "" Then
.TypeText Text:="Phone: " & strPhone
.TypeParagraph
End If
If strFax <> "" Then
.TypeText Text:="Fax: " & strFax
.TypeParagraph
End If
If strCell <> "" Then
.TypeText Text:="Cell: " & strCell
.TypeParagraph
End If
If strEmail <> "" Then
.TypeText Text:="Email: " & strEmail
.TypeParagraph
End If
End With
UserCancelled:
End Sub

will insert the addresses more or less as you require them.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

Bob Buckland ?:-\)

Hi Graham,


This is certainly a strange one :)

FWIW, in the original example,
where the AddressLayout includes
{<PR_LOCALITY>}
(for City code) the content of field(s) on the last line in the AddressLayout don't appear in a document.

It doesn't seem to matter if it's the Email address or Cell phone # that's on the last row.

In your macro I noticed you used
{<PR_POSTAL_ADDRESS>}
When I substituted that for the line in the original of
{<PR_LOCALITY>}, {<PR_STATE_OR_PROVINCE>} {<PR_POSTAL_CODE>}
or just remove the {<PR_LOCALITY>}
field code then the content of the last field shows up. :)

It seems to be that particular field rather than a change in the # of fields in that case, but just to try a couple of variations,
if I cut and pasted the {<PR_COMPANY_NAME>} field to be the last line, the last line it stopped showing up again.

=====================
Further to my last:

Public Sub InsertAddressFromOutlookA()
Dim strTitle As String
Dim strJobTitle As String
Dim strForeName As String
Dim strSurname As String
Dim strCompany As String
Dim strAddress As String
Dim strCountry As String
Dim strPhone As String
Dim strFax As String
Dim strCell As String
Dim strEmail As String
Dim strFinal As String

'Set up the formatting codes in strCode
strTitle = "{<PR_DISPLAY_NAME_PREFIX> }"
strJobTitle = "<PR_TITLE>"
strForeName = "{<PR_GIVEN_NAME> }"
strSurname = "<PR_SURNAME>"
strCompany = "<PR_COMPANY_NAME>"
strAddress = "<PR_POSTAL_ADDRESS>"
strCountry = "<PR_COUNTRY>"
strPhone = "<PR_OFFICE_TELEPHONE_NUMBER>"
strFax = "<PR_BUSINESS_FAX_NUMBER>"
PstrCell = "<PR_CELLULAR_TELEPHONE_NUMBER>"
strEmail = "<PR_EMAIL_ADDRESS>"

'Let the user choose the name in Outlook
On Error GoTo UserCancelled:
strAddress = Application.GetAddress("", strAddress, _
False, 1, , , True, True)
If strAddress = "" Then
MsgBox "User cancelled or no address listed", , "Cancel"
Exit Sub
End If
strTitle = Application.GetAddress("", strTitle, _
False, 2, , , True, True)
strForeName = Application.GetAddress("", strForeName, _
False, 2, , , True, True)
strSurname = Application.GetAddress("", strSurname, _
False, 2, , , True, True)
strCompany = Application.GetAddress("", strCompany, _
False, 2, , , True, True)
strJobTitle = Application.GetAddress("", strJobTitle, _
False, 2, , , True, True)
strCountry = Application.GetAddress("", strCountry, _
False, 2, , , True, True)
strPhone = Application.GetAddress("", strPhone, _
False, 2, , , True, True)
strFax = Application.GetAddress("", strFax, _
False, 2, , , True, True)
strCell = Application.GetAddress("", strCell, _
False, 2, , , True, True)
strEmail = Application.GetAddress("", strEmail, _
False, 2, , , True, True)

strFinal = strTitle & Left(strForeName, 1) & " " & strSurname & vbCr

If strCompany <> "" Then
strFinal = strFinal & strCompany & vbCr
If strJobTitle <> "" Then
strFinal = strFinal = strFinal & strJobTitle & vbCr
End If
End If

If InStr(strCountry, "United States") Then
strAddress = Left(strAddress, Len(strAddress) - 25)
End If
With Selection ' type in the name string _
using the Inside Address paragraph style
.Style = ActiveDocument.Styles("Normal")
.TypeText Text:=strFinal
.TypeText Text:=strAddress
.TypeParagraph
If strPhone <> "" Then
.TypeText Text:="Phone: " & strPhone
.TypeParagraph
End If
If strFax <> "" Then
.TypeText Text:="Fax: " & strFax
.TypeParagraph
End If
If strCell <> "" Then
.TypeText Text:="Cell: " & strCell
.TypeParagraph
End If
If strEmail <> "" Then
.TypeText Text:="Email: " & strEmail
.TypeParagraph
End If
End With
UserCancelled:
End Sub

will insert the addresses more or less as you require them.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Curiouser and curiouser. However I prefer to use the postal address field,
and while it should not display the home country it sometimes does. The
original AddressLayout also had a number of unnnecessary and misplaced
'field' brackets. It works with

{<PR_DISPLAY_NAME>

}{<PR_TITLE>

}{<PR_COMPANY_NAME>

}<PR_POSTAL_ADDRESS>

{Phone: <PR_OFFICE_TELEPHONE_NUMBER>

}{Fax: <PR_BUSINESS_FAX_NUMBER>

}{Cell: <PR_CELLULAR_TELEPHONE_NUMBER>

}{Email: <PR_EMAIL_ADDRESS>}



and although the macro posted earlier works, it has a lot of accesses to
Outlook which could be reduced to speed it up.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

And would work even better single spaced ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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