Pull fields from one contact record into Word

G

Grant B

I would like to have Word templates that would auto fill from Outlook. For
example, when I have "Bill Smith" contact open (or selected or whatever),
opening a template would fillin the name "Bill Smith." I want to do these one
at a time, not an entire mailmerge. Any suggestions?
 
G

Grant B

I'm familiar with Mailmerge. What I'm really looking for is the capability I
had in Goldmine of creating documents that would pull from the open contact.
For example, having a "new letter" template (or document) that, when opened,
would automatically enter the name, address, and "Dear" from Outlook. Just
one document, one contact at a time. I'm surprised that I have not been able
to find a way to do that.

Any other ideas... anyone?

Thanks,
Grant
 
D

Doug Robbins - Word MVP

The following code runs from Outlook and will populate docvariable fields
for the variables listed in the code that are located in the template with
the data from the selected Outlook contact:

Dim objitem As Object
Dim cFullName As String
Dim cCompanyName As String
Dim cBusinessAddressStreet As String
Dim cBusinessAddressCity As String
Dim cBusinessAddressState As String
Dim cBusinessAddressZip As String
Dim oWord As Word.Application
Dim WordNotRunning As Boolean
Dim oDoc As Document
Set objitem = GetCurrentItem()
If objitem.Class = olContact Then
With objitem
cFullName = .FullName
cCompanyName = .CompanyName
cBusinessAddressStreet = .BusinessAddressStreet
cBusinessAddressCity = .BusinessAddressCity
cBusinessAddressState = .BusinessAddressState
cBusinessAddressZip = .BusinessAddressPostalCode
End With
End If
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then 'Word was not running
Set oWord = New Word.Application
WordNotRunning = True
End If

Set oDoc = oWord.Documents.Add("TemplateName.dot")
oWord.Visible = True
oWord.Activate
With oDoc
.Variables("varFullName").Value = cFullName
If cCompanyName <> "" Then
.Variables("varCompanyName").Value = cCompanyName
Else
.Variables("varCompanyName").Value = " "
End If
If cBusinessAddressStreet <> "" Then
.Variables("varStreet").Value = cBusinessAddressStreet
Else
.Variables("varStreet").Value = " "
End If
If cBusinessAddressCity <> "" Then
.Variables("varCityStateZip").Value = cBusinessAddressCity & ", " &
cBusinessAddressState & " " & cBusinessAddressZip
Else
.Variables("varCityStateZip").Value = " "
End If
.Range.Fields.Update
End With
If WordNotRunning Then
oWord.Documents.Close wdDoNotSaveChanges
oWord.Quit
End If
Set oWord = Nothing
Set olabel = Nothing

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Grant B

Sweet, Doug. I think I'm getting closer, but you went a little over my head.
I'm not sure how to get the code into Outlook.

It looks like I'd build a Word template and reference the Outlook fields I
need, then get Outlook to open the template and fill with my data.

Can you explain how to get it into Outlook or should we explore the "paid
consultant" idea?
 
D

Doug Robbins - Word MVP

The method is very similar to that described in the article "What do I do
with macros sent to me by other newsgroup readers to help me out?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

except that from the Tools menu in Outlook, you select Macro and then
Macros. In the case of Outlook however, there is no option to choose a
template in which to create the macros.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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