View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Pull fields from one contact record into Word

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

"Grant B" wrote in message
...
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

"Graham Mayor" wrote:

Outlook's Tools Mailmerge will do that see
http://www.gmayor.com/mailmerge_from_outlook.htm
or see http://www.gmayor.com/Macrobutton.htm for a method of calling data
from Outlook whilst working in Word.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Grant B wrote:
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?