Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
word - Mail Merge to New Document
#1
I'm switching over a mail label file from a dot matrix formatted file to labels on a laserjet.

I'd like to write an exe to drag and drop the original mail label file for the dot matrix that will create a .doc file ready to print.


So far...
I've gotten a tab separated file containing the data using QM and some regex.

I've been able to create the correct mail merge document using the mail merge wizard.

So now I have a .txt file with the data, and a .doc file that is a template.

There is a mail merge toolbar in word that has a button that is "Merge to New Document" to send "All" records to a new .doc

So the question...
How to use QM to automate merging all of the data to the new document?

Thanks,
jim
#2
Found some stuff. Still haven't gotten it to work, but:
Function WordMailMerge
Code:
Copy      Help
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Document d._getfile(_s.expandpath(WordDoc))
d.MailMerge.Destination=wdSendToNewDocument
d.MailMerge.Execute()
#3
I'm also wondering if the MailMerge should all be handled with code instead of a document set up through the wizard.

Any advice?
#4
This page looks like it is doing what I will need:
http://support.microsoft.com/kb/258512

Help converting to QM?

-jim
#5
So I'm still stuck on this.

Function WordMerge
Code:
Copy      Help
;Open WordDoc, MailMerge with DataDoc, and output formatted MergedDoc

str WordDoc="$desktop$\LaserJet.doc"
str DataDoc="$desktop$\data.txt"
str MergedDoc="$desktop$\Merged.doc"

WordDoc.expandpath
DataDoc.expandpath
MergedDoc.expandpath

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application oApp._create
Word.Document d._getfile(_s.expandpath(WordDoc))

d.MailMerge.OpenDataSource(DataDoc)
d.MailMerge.Destination= wdSendToNewDocument
d.MailMerge.Execute()


;;HOW TO SAVE AS MergedDoc?...
#6
Perhaps wdSendToPrinter for the MailMerge.Destination would work, but I'd need to have the user be able to select the printer.

When I run the following function it just prints to the default printer without prompting:
Function WordMerge
Code:
Copy      Help
;Open WordDoc, MailMerge with DataDoc, and output formatted MergedDoc

str WordDoc="$desktop$\MailMerge.doc"
str DataDoc="$desktop$\data.txt"
str MergedDoc="$desktop$\Merged.doc"

WordDoc.expandpath
DataDoc.expandpath
MergedDoc.expandpath

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application oApp._create
Word.Document d._getfile(WordDoc)
d.MailMerge.OpenDataSource(DataDoc)
d.MailMerge.Destination= wdSendToPrinter
d.MailMerge.Execute()
d.Close

Also, the WINWORD.exe is still running after this function runs. How do you properly close the document? I think it must be the merged document that is staying open...or something.
#7
And how do you close without saving changes?
#8
figured it out.

Function WordMerge
Code:
Copy      Help
WordDoc.expandpath
DataDoc.expandpath
MergedDoc.expandpath

typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application oApp._create
Word.Document d._getfile(WordDoc)
d.MailMerge.OpenDataSource(DataDoc)
d.MailMerge.Destination= wdSendToNewDocument
d.MailMerge.Execute()

IDispatch app._getactive("Word.Application")
VARIANT v=MergedDoc
VARIANT save=FALSE

app.ActiveDocument.SaveAs(v)
app.ActiveDocument.Close(save)


d.Close(save)
oApp.Quit


Forum Jump:


Users browsing this thread: 1 Guest(s)