Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2017, 08:26 AM
Leftovercity Leftovercity is offline Macro Code for Duplex Printing Mac OS X Macro Code for Duplex Printing Office 2016
Novice
Macro Code for Duplex Printing
 
Join Date: Jan 2017
Posts: 3
Leftovercity is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 01-26-2017, 04:03 PM
macropod's Avatar
macropod macropod is offline Macro Code for Duplex Printing Windows 7 64bit Macro Code for Duplex Printing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,319
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-26-2017, 04:16 PM
Leftovercity Leftovercity is offline Macro Code for Duplex Printing Mac OS X Macro Code for Duplex Printing Office 2016
Novice
Macro Code for Duplex Printing
 
Join Date: Jan 2017
Posts: 3
Leftovercity is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-27-2017, 12:30 AM
gmayor's Avatar
gmayor gmayor is offline Macro Code for Duplex Printing Windows 10 Macro Code for Duplex Printing Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,153
gmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of light
Default

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
Reply With Quote
  #5  
Old 01-27-2017, 10:43 AM
Leftovercity Leftovercity is offline Macro Code for Duplex Printing Mac OS X Macro Code for Duplex Printing Office 2016
Novice
Macro Code for Duplex Printing
 
Join Date: Jan 2017
Posts: 3
Leftovercity is on a distinguished road
Default

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!
Reply With Quote
Reply

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
Macro Code for Duplex Printing 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
Macro Code for Duplex Printing 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

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft