H
Huisie
I have 2 questions regarding the above:
I want to insert the following into a Word template using a Macrobutton:
"Company Name" OR "Display Name"
"Postal Address"
(open line)
"Phone No"
"Fax No"
Using the excellent examples from Graham Mayor
(http://www.gmayor.com/Macrobutton.htm) and supplementary info from MVPS.org
(http://word.mvps.org/FAQs/TblsFldsFms/InsertAdrsWMacroFld.htm), I came up
with the following:
Public Sub InsertAddressFromOutlook()
Dim strCode, strAddress As String
'Set up the formatting codes in strCode
strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
strCode = strCode & "<PR_POSTAL_ADDRESS>" & vbCr & vbCr
strCode = strCode & "{TEL: {<PR_OFFICE_TELEPHONE_NUMBER>}}" & vbCr
strCode = strCode & "{FAX: {<PR_BUSINESS_FAX_NUMBER>}}"
'strCode = strCode & "<PR_LOCALITY>, <PR_STATE_OR_PROVINCE>
<PR_POSTAL_CODE>" & vbCr
'strCode = strCode & "<PR_COUNTRY>" & vbCr
'Let the user choose the name in Outlook
strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)
'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
Selection.Range.Text = strAddress
'Insert the modified address at the current insertion point
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
ActiveDocument.FormFields("NameOfFormfield").Result = strAddress
Else
Selection.TypeText strAddress
End If
End Sub
Question 1
-------------
I can't create the "OR" option in VBA.
With reference to Slipstick.com
(http://www.slipstick.com/contacts/insword.htm), this is enabled via typing
"|" between two adress fields.
When I type this option into my macro code, it all goes pear-shaped...
Question 2
-------------
You'll notice that I included 2 options for:
"Insert the modified address at the current insertion point"
They both work fine - is there any benefit using the seemingly more complex
2nd option?
Thanks in advance for any help and especially to those who posted and
allowed me to cut 'n paste their examples.
Would have been lost in the wilderness without your generosity.
I want to insert the following into a Word template using a Macrobutton:
"Company Name" OR "Display Name"
"Postal Address"
(open line)
"Phone No"
"Fax No"
Using the excellent examples from Graham Mayor
(http://www.gmayor.com/Macrobutton.htm) and supplementary info from MVPS.org
(http://word.mvps.org/FAQs/TblsFldsFms/InsertAdrsWMacroFld.htm), I came up
with the following:
Public Sub InsertAddressFromOutlook()
Dim strCode, strAddress As String
'Set up the formatting codes in strCode
strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
strCode = strCode & "<PR_POSTAL_ADDRESS>" & vbCr & vbCr
strCode = strCode & "{TEL: {<PR_OFFICE_TELEPHONE_NUMBER>}}" & vbCr
strCode = strCode & "{FAX: {<PR_BUSINESS_FAX_NUMBER>}}"
'strCode = strCode & "<PR_LOCALITY>, <PR_STATE_OR_PROVINCE>
<PR_POSTAL_CODE>" & vbCr
'strCode = strCode & "<PR_COUNTRY>" & vbCr
'Let the user choose the name in Outlook
strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)
'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
Selection.Range.Text = strAddress
'Insert the modified address at the current insertion point
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
ActiveDocument.FormFields("NameOfFormfield").Result = strAddress
Else
Selection.TypeText strAddress
End If
End Sub
Question 1
-------------
I can't create the "OR" option in VBA.
With reference to Slipstick.com
(http://www.slipstick.com/contacts/insword.htm), this is enabled via typing
"|" between two adress fields.
When I type this option into my macro code, it all goes pear-shaped...
Question 2
-------------
You'll notice that I included 2 options for:
"Insert the modified address at the current insertion point"
They both work fine - is there any benefit using the seemingly more complex
2nd option?
Thanks in advance for any help and especially to those who posted and
allowed me to cut 'n paste their examples.
Would have been lost in the wilderness without your generosity.