Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Office automation

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
I am trying to print a word document from within a VFP application, using the following code.


#DEFINE wdSendToPrinter 1
.
.
.
oWord.ActiveDocument.MailMerge.Destination = wdSendToPrinter


It works fine, but I would like to direct the oputput to a non-default printer. My application can pass the printer name. What I need is the syntax to pass it to MSWord.

Thanks,
Sam
 
I've seen this issue before, but can't remember exactly how I solved it.

I'll look into it further, but, in the meantime, have your tried simply setting the ActivePrinter property to the name of the printer (that is, the string returned from GEPRINTER()). ActivePrinter is a property of the Word application object (oWord in your example).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks Mike,

Here is my next question please.
I use the code below to open and merge documents in MSWord. Both the template and merged document show up. The template is untitled. It shows "Document1 (Compatibility Mode)" on the very top line of the screen.

Is it possible to pass the actual name of the document? ie. gcTxtDocFile

Thanks, Sam

CODE:
***********************************
* Setup and activate Word
oWord = CREATEOBJECT("Word.Application")
oDocument = oWord.Documents.ADD( gcTxtDocFile ) && document file location and file name
oWord.ActiveDocument.MailMerge.OpenDataSource(gcTxtDatFile) && .dat file location and file name

oWord.ACTIVATE()
oWord.VISIBLE = .T. && Show word

* Perform the mail merge and display the document in Word for editing
oDocument.MailMerge.Execute()
***********************************
 
Sam,

After you run oDocument.MailMerge.Execute(), the merge document will be the active document. You only need to call its SaveAs method, passing the name that you want to give it. For example:

Code:
oWord.ActiveDocument.SaveAs("c:\documents\MyMailMerge.doc")

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks.

That was nice and easy.

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top