Read merged file

A

Abraet

I have a mail merge file that I now want to read as input to find a customer
number and then look up more info on that customer to determine if the merged
document should be printed, faxed or emailed depending on the customer's
preference. I can read a bookmark field from Word fine, but it doesn't seem
to keep the bookmark from the master document when creating the word
document. Now I'm trying to use the find property to find a text word label
then calculate the location of the data relative to the label, but not sure
I'm going about it right. Here's my starter code. Any suggestions??


MSWord.Documents.Open(CurrentFile)
MSWord.Activate
Selection.WholeStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "CustNbr"
End With
Selection.Find.Execute
' look for "Cust Number " then add 13 to get to start of data.
CustNbrFieldBeginRange = Selection.Range.start + 13
' Cust number is 9 characters so end at
CustNbrFieldEndRange = CustNbrFieldBeginRange + 9
Set
CustNbr = **Here I'm not sure how to reference new range to pick up value
of data from calculated range ***
Call MSWord.ActiveDocument.Close
 
D

Doug Robbins - Word MVP

Dim CustNumber as Range
MSWord.Documents.Open(CurrentFile)
MSWord.Activate
Selection.WholeStory
Selection.Find.ClearFormatting
With Selection.Find
..Text = "CustNbr"
End With
Selection.Find.Execute
Set CustNumer = Selection.Range
CustNumber.Range.End=CustNumber.Range.End + 22
CustNumber.Range.Start=CustNumber.Range.Start + 13
MsgBox CustNumber


--
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