Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Print to File (Word XP SR1)

    We often print to file by using a printer specific to this purpose which has its port set to File. When printing to this printer, Word XP (unlike Word 97) set ths Print to File option on the print dialog to True. Thus, after our VBA code has printed to file, that option remains set to True. The user must remember to de-select it when next printing.

    Is there a way to set Print to File to false without doing it as part of a command to Print?

    Thanks,
    Richard Barrett

  2. #2
    New Lounger
    Join Date
    Jan 2002
    Location
    South of Redmond
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print to File (Word XP SR1)

    Richard,

    Piece of cake, if you're willing to revisit your VBA code. We're doing the same thing (Word 2002, custom printer driver with port set to File, using VBA to help out the users with a toolbar button). With the driver's port set to File, the "Print to file" checkbox in the File Print dialog box is unnecessary. The trick is to store the name of the current printer before you start, then restore it later. Here's the key bit of code that will do what you need:

    Sub PrintFile()

    Dim strDefPrinter As String

    ' Store name of default printer so it can be restored later.
    strDefPrinter = Application.ActivePrinter
    ' Change the active printer for this job.
    Application.ActivePrinter = (printername as string)
    ' Print to file
    ActiveDocument.PrintOut OutputFileName:=(path and filename as string), PrintToFile:=True
    ' Restore default printer.
    Application.ActivePrinter = strDefPrinter

    End Sub

    A note of warning: When READING the ActivePrinter property, Word returns what's in its own File Print dialog box (whether or not that printer is the current default system printer), but when WRITING the ActivePrinter property, it broadcasts the change to the OS and all open apps--in other words, it changes the current default system printer. This rarely is an issue, but you should keep it in mind if you get unexpected results from time to time. The alternative is to use API to accomplish the same thing more gracefully.

    Hope this helps,

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Print to File (Word XP SR1)

    This is exactly what my code does. I used this successfully in Word 97 and Word 2000. The problem is apparently unique to Word XP. We do not set Print to File to True; the printer has its port set to File. But Word makes that change internally (when printing to this printer, the Print to File option gets checked), and we can't find a way to un-do it.

  4. #4
    Lounger
    Join Date
    Apr 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print to File (Word XP SR1)

    To prevent the system default printer being changed try using this piece of code

    strDefPrinter = Application.ActivePrinter
    With Dialogs(wdDialogFilePrintSetup)
    .Printer = "Printer Name"
    .DoNotSetAsSysDefault = True
    .Execute
    End With
    Application.PrintOut
    Application.ActivePrinter = strDefPrinter

    You may also be able to use this type of code to turn off the Print to File option after the print


    Belinda

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •