简体   繁体   中英

How to select “print on both sides” in MS Word 2013 vba

I'd like to be able to programmatically select the double sided button in MS Word 2013 printpreview in backoffice view via vba.

I am unable to get the PCL6 code to work with our sharp MFC. Some documents I want to have it print double sided by default but not on all documents. I can't find the ExecuteMso button for this as the backoffice view doesn't seem to be accessible via vba code. Perhaps using WinAPI would work or sendkeys but I think that's messy and unreliable.

打印预览的后台视图,其中突出显示了双面选项

You can control printing on one side or both sides with an option called: ManualDuplexPrint . Set it to False and it will print both sided.

Let's say that you want to print the whole document both sided. You would write:

Sub test()
    ThisDocument.PrintOut Range:=wdPrintAllDocument, ManualDuplexPrint:=False
End Sub

Please don't forget to hit the check mark next to the question if this is the answer! :)

When you record a macro and print using the duplex options, it does not capture duplex in the dialog. This is the macro that was generated when I double-sided a test document:

ActivePrinter = "\\MyServer\MyHPPrinter"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
        wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0

During the recording of the Macro, the document printed duplex. When I closed/reopened the document and ran the Macro, it printed one-sided. Using Word from Office 365 and printing to HP Laser Jet9050dn. I also tried adding , ManualDuplexPrint:=False after wdPrintAllPages. This did nothing for me.

If this was formatted incorrectly, please forgive me.... this is my first post here.

I Found a workaround for duplex Printing. Word doesn't support the option for Automatic duplex printing rather it is printer specific which loads the options if a printer supports it.

  • Install a copy version of the printer driver on your pc. I found great help for this from here .

  • Follow the procedure and install the driver. Rename it (Use Duplex for easy understanding).

  • Go to printing preference and set the duplex setting as default.

  • Now make that printer active in your VBA code.

    ActivePrinter = "Brother DCP Duplex"

     Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _ wdPrintDocumentWithMarkup, Copies:=1, Pages:="s1", PageType:= _ wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _ PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _ PrintZoomPaperHeight:=0
  • No need for ManualDuplexPrint:=False .

I tried it myself and works perfectly.

Happy Coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM