The following macrosaved in the form template and run on entry to the
address form field will prompt for the address from Outlook or if cancelled,
allow the user to manually complete the address. I have included all the
fields to insert name, company and address. You can include only what is
required. The macro assumes the address field is Text1 and that your home
country is the USA. Change the two instances of Text1 to the name of the
address field if different. If you have a different Home Country, you would
need to change the lines
If InStr(strCountry, "United States") Then
strAddress = Left(strAddress, Len(strAddress) - 18)
to reflect the name of the Country as it appears in Outlook and the length
of the name in place of 18.
http://www.gmayor.com/installing_macro.htm
Public Sub InsertAddressFromOutlook()
Dim strTitle As String
Dim strForename As String
Dim strSurname As String
Dim strCompany As String
Dim strAddress As String
Dim strCountry As String
Dim strFinal As String
'Set up the formatting codes in strCode
strTitle = "{<PR_DISPLAY_NAME_PREFIX> }"
strForename = "{<PR_GIVEN_NAME> }"
strSurname = "<PR_SURNAME>"
strCompany = "<PR_COMPANY_NAME>"
strAddress = "<PR_POSTAL_ADDRESS>"
strCountry = "<PR_COUNTRY>"
'Let the user choose the name in Outlook
strAddress = Application.GetAddress("", strAddress, _
False, 1, , , True, True)
If strAddress = "" Then
MsgBox "User cancelled or no address listed." & vbCr & _
"Type the address in the field", , "Cancel"
ActiveDocument.FormFields("Text1").Result = ""
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)
strCountry = Application.GetAddress("", strCountry, _
False, 2, , , True, True)
strFinal = strTitle & strForename & strSurname
If strFinal <> "" Then strFinal = strFinal & vbCr
If strCompany <> "" Then
strFinal = strFinal & strCompany & vbCr
End If
If InStr(strCountry, "United States") Then
strAddress = Left(strAddress, Len(strAddress) - 18)
End If
ActiveDocument.FormFields("Text1").Result = strFinal & strAddress
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>