Insert one address from contacts in document

  • Thread starter Thread starter frank
  • Start date Start date
F

frank

How do I insert one contact into a document under my own
address format:
Company Name
Full Name
Business Address
Business Phone
Business Fax

Knowledge base 212345 provides info on this subject;
however, it does not seem to work for me.

Could someone guide me step by step??
Thanks
Frank
 
' Look up a name and address and insert it into the current document at the
' current insertion point
'
Public Sub InsertNameFromList()

Const STYLE_A as string = "Normal NoLead" 'Lines other than
last: 0 before, 0 after
Const STYLE_B as string = "Normal" 'Last line:
0 before, 6 after

Dim pText As String
Dim pLayout As String
Dim pData() As String
Dim pIndex As Long

'Define the required format
pLayout = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & _
"<PR_COMPANY_NAME>" & vbCr & _
"<PR_STREET_ADDRESS>" & vbCr & _
"<PR_LOCALITY>" & " " & "<PR_STATE_OR_PROVINCE>" & " " &
"<PR_POSTAL_CODE>"

'Fetch the address in the required format
pText = Application.GetAddress(AddressProperties:=pLayout)

'Insert into document unless not found or cancelled
If Len(pText) > 0 Then

'Split into lines
pData = Split(pText, vbCr)

'Insert the name: style A
Selection.Style = ActiveDocument.Styles(STYLE_A)
Selection.TypeText Text:=pData(0)
Selection.TypeParagraph

'Loop through the remaining lines
For pIndex = 1 To UBound(pData)

'Last line: Style_B, no trailing paragraph
If pIndex = UBound(pData) Then
Selection.Style = ActiveDocument.Styles(STYLE_B)
Selection.TypeText Text:=pData(pIndex)

'Not last line: Style_A inherited from previous line, add
trailing paragraph
Else
Selection.TypeText Text:=pData(pIndex)
Selection.TypeParagraph
End If

Next

End If

End Sub
 
Thanks for the quick response!
However I have no idea what to do with the information
you gave me.
If you could please tell me what to do with this info.
Thanks Frank


-----Original Message-----

' Look up a name and address and insert it into the current document at the
' current insertion point
'
Public Sub InsertNameFromList()

Const STYLE_A as string = "Normal
NoLead" 'Lines other than
last: 0 before, 0 after
Const STYLE_B as string
= "Normal" 'Last line:
 
Back
Top