How do I insert an Outlook address into Word when the doc is locke

J

jbr76

I am creating a transmittal form for my company that I want it to have an
option of manually adding an address or inserting one from Outlook. I have
many fields in this template to make it easy for people to fill out. When I
have the file locked, I can't add addresses. I need it locked so the
formating doesn't get messed up. I have tried
 
G

Graham Mayor

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

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