Word automation from Visual Foxpro:  How to set printer

Posted on 2011-05-13
Last Modified: 2016-02-22
WORD 2007

We are happily using automation to create WORD docs within VFP and edit or print them.

I am now trying to use Word for multiple mail-merged letters, and need to set the printer for use.

Skeleton code is:

oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .f.

oDocument = oWord.Documents.Open(m.saveAsName)
oRange = oWord.ActiveDocument.Range(0,0)

   word_findreplace( "contact",

   word_findreplace( "ad1", ad_array[1])
   word_findreplace( "ad2", ad_array[2])



We obtain a printer ID with the Foxpro getprinter() method.


I fondly imagined that this would work:

oDocument.activeprinter = 'PDFcreator'

but it doesn't, so any ideas welcome.

Nick Cutler
Question by:peterduck
    LVL 76

    Expert Comment

    I suspect that PDFCreator is a virtual printer, you so probably need to supply a file name.

    Have you tried it with a physical printer?

    LVL 76

    Expert Comment

    The fourth parameter of the printout method is named OutPutFileName.

    I don't have PDFCreator, and the last time I used Foxpro it was a DOS version, so I can't get you any closer than that.    

    Accepted Solution

    Problem solved !  I was being stupid:

    The active printer belongs to oWord, not oDocument.

    oWord.activeprinter = thisform.printer  works ok

    LVL 76

    Expert Comment

    I should have spotted that. Duh!

    Author Comment

    I've been there lots of times - and thanks anyway,

    LVL 13

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
    This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now