#1
|
|||
|
|||
Macro Code for Duplex Printing
Hi Everyone, First time on here. I'm new to Macros but got one working that creates sequential numbering page to page. But now my issues is that the document I need it for is two pages and I need it to be printed two sided (Duplex). When I run the Macro it bypasses the printer setting window and prints two individual pages. Is there a Macro code I can add to run duplex printing? Here's my current code: Code:
Dim Message As String, Title As String, Default As String, NumCopies As Long Dim Rng1 As Range ' Set prompt. Message = "Enter the number of copies that you want to print" ' Set title. Title = "Print" ' Set default. Default = "1" ' Display message, title, and default value. NumCopies = Val(InputBox(Message, Title, Default)) SerialNumber = System.PrivateProfileString("C:\Settings.Txt", _ "MacroSettings", "SerialNumber") If SerialNumber = "" Then SerialNumber = 1 End If Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range Counter = 0 While Counter < NumCopies Rng1.Delete Rng1.Text = Format(SerialNumber, "0000") ActiveDocument.PrintOut SerialNumber = SerialNumber + 1 Counter = Counter + 1 Wend 'Save the next number back to the Settings.txt file ready for the next use. System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _ "SerialNumber") = SerialNumber 'Recreate the bookmark ready for the next use. With ActiveDocument.Bookmarks .Add Name:="SerialNumber", Range:=Rng1 End With ActiveDocument.Save Last edited by macropod; 01-26-2017 at 03:54 PM. Reason: Added code tags and formatting |
#2
|
||||
|
||||
The ActiveDocument.PrintOut method does not take an argument for setting duplex vs simplex printing. Accordingly, you would either have to use a different method or pre-configure the printer for duplex printing. Although it's possible to pre-configure the printer for duplex printing through VBA, the commands required for this are specific to the type of printer being used. Alternatively, you could embed a PRINT field with the duplexing command into the document itself. For example, for printing documents to Hewlett-Packard (HP) or HP-compatible printers, a PRINT field coded as {PRINT 27"&l2S"} at the top of a page causes a duplexing printer to begin printing on both sides of the page, using short-edge binding. See Insert|Quick Parts|Field.
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had. Inserting asterisks for spacing as you did makes the code impossible to work with.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
macropod, Thank you! I'll look into that, this is a Xerox Workcentre 7525. For now I'm doing the old fashioned way of printing all on one side then flipping the pages and re-inserting in to the printer to print the other side. Appreciate the help.
|
#4
|
||||
|
||||
The Xerox Workcentre 7525 appears to support both PCL language and Postscript, so it is probable that you can send a PRINT command to the printer from the document to instruct it to print duplex. A PRINT field is simply a type of field that allows you to send instructions directly to the printer.
There are 3 possible data values for duplex setting: PRINT 27"&l0S" simplex PRINT 27"&l1S" vertical duplex . PRINT 27"&l2S" horizontal duplex (bookformat) Use CTRL+F9 for the brackets {}. The codes after PRINT are 27 (escape), double quote, ampersand, lowercase L, 0, 1 or 2, uppercase S and finally terminated with a double quote. Thus for horizontal duplex you would insert the following field : { PRINT 27"&l2S" }
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Thank you! You are a wizard! I couldn't get the code to work but I was able to download additional drivers from Xerox that allowed it to print duplex by default. I'm blown away by all of this. Huge learning curve, but starting to get it. I can't tell you how many times I've had to do this numbering by hand. Huge saver. Thanks to both of you!
|
Tags |
duplex, macro edit |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Stop duplex printing | NuDawn | Word | 0 | 12-28-2016 09:06 AM |
Mixed Duplex Printing | jaygreg | Word | 2 | 01-29-2014 09:54 AM |
Printing calendar pages with duplex | cma6 | Outlook | 0 | 12-06-2012 07:29 AM |
Duplex printing | fireman0174 | Word | 1 | 09-26-2011 01:44 AM |
Duplex Printing a merge doc | AshlandMark | Word | 0 | 02-10-2009 12:29 PM |