Posts: 1,000
Threads: 253
Joined: Feb 2008
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
Posts: 1,000
Threads: 253
Joined: Feb 2008
Found some stuff. Still haven't gotten it to work, but:
Function
WordMailMerge
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Document d._getfile(_s.expandpath(WordDoc))
d.MailMerge.Destination=wdSendToNewDocument
d.MailMerge.Execute()
Posts: 1,000
Threads: 253
Joined: Feb 2008
I'm also wondering if the MailMerge should all be handled with code instead of a document set up through the wizard.
Any advice?
Posts: 1,000
Threads: 253
Joined: Feb 2008
This page looks like it is doing what I will need:
http://support.microsoft.com/kb/258512
Help converting to QM?
-jim
Posts: 1,000
Threads: 253
Joined: Feb 2008
So I'm still stuck on this.
Function
WordMerge
;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?...
Posts: 1,000
Threads: 253
Joined: Feb 2008
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
;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.
Posts: 1,000
Threads: 253
Joined: Feb 2008
And how do you close without saving changes?
Posts: 1,000
Threads: 253
Joined: Feb 2008
figured it out.
Function
WordMerge
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