![]() |
|
#10
|
|||
|
|||
|
Absolutely not a worry with the delay in your reply, was kind of expecting it - and the wait was worth it!
After a very minor change to three lines of your code (highlighted below) it most certainly works at home so massive thanks. Will try tomorrow at work and see what happens. Code:
Sub PrintNumberedCopiesEntireDocument()
'
' PrintNumberedCopiesEntireDocument Macro
' Shortcut keys Alt+E
'
Const cdp_name As String = "CopyNum"
Const default_copies As String = "1"
Const duplex_printer As String = "hp deskjet 5550 series (HPA) duplex" ' change this to the name of your duplex printer
Dim my_form As ufrmPrintNumberedCopies
Dim copy_number As Long
Dim first_copy As Long
Dim last_copy As Long
Dim my_update_fields_at_print As Boolean
Dim my_update_link_at_print As Boolean
Dim current_printer As String
' We are using a custom Document Property to save the serial number
' as we can edit this from the backstage properties advanced dialog
' if needed
ensure_cdp_exists cdp_name
Set my_form = New ufrmPrintNumberedCopies
With my_form
.txtStartNumber = Trim(ActiveDocument.Variables(cdp_name))
.txtCopies = default_copies
.Show
If Not .Result Then
Exit Sub
End If
End With
' We now switch to the document printer that has been customised to aleays
' print in duplex
current_printer = ActivePrinter
ActivePrinter = duplex_printer
' The update fields and links at print time are application properties so anly need setting once
' but we preserve the values so we can restore the current settings after we have finished printing
With Options
my_update_fields_at_print = .UpdateFieldsAtPrint
.UpdateFieldsAtPrint = True
my_update_link_at_print = .UpdateLinksAtPrint
.UpdateLinksAtPrint = True
End With
first_copy = CLng(Trim(my_form.txtStartNumber))
last_copy = first_copy + CLng(Trim(my_form.txtCopies)) - 1
' MsgBox "Now we do the printing", vbOKOnly 'comment this out once tested
' it is assumed that there is a field somewhere that references the customdocumentproperty
For copy_number = first_copy To last_copy ' uncomment the for loop once tested
ActiveDocument.Variables(cdp_name) = CStr(copy_number)
ActiveDocument.PrintOut copies:=1
Next
' save the next starting serial number
ActiveDocument.Variables(cdp_name) = last_copy + 1
' snipped as the remainder of the code is not changed
This is the code that was being used: Code:
Sub PrintNumberedCopiesSelectionofPages()
'
' PrintNumberedCopiesSelectionofPages Macro
' Shortcut Key Alt+S
'
Dim Msg As String, Ans As Long
Dim lCopiesToPrint As Long
Dim lCounter As Long
Dim lCopyNumFrom As Long
Dim strPages As String
Ans = MsgBox(Space(1) & "Is the document print settings configured for 'Print on Both Sides?" & vbCrLf & vbCrLf & _
"If not then click 'No', click the 'File' tab, 'Print', select 'Print on Both Sides / Flip pages on long edge' and then press 'Alt+S'.", _
vbMsgBoxSetForeground + vbQuestion + vbYesNoCancel, (Space(50) & "ABCDF 1234" & Application.Name))
Select Case Ans
Case vbYes
Case vbNo
End
Case vbCancel
End
End Select
' ask how many to print
On Error GoTo Canceled
lCopiesToPrint = InputBox( _
prompt:="How many copies do you require?", _
Title:=(Space(45) & "ABCDF 1234"), _
Default:="1")
' ask where to start numbering
On Error GoTo Canceled
lCopyNumFrom = InputBox( _
prompt:="Number at which to start numbering copies?", _
Title:=(Space(45) & "ABCDF 1234"), _
Default:=CStr(ActiveDocument.Variables("CopyNum") + 1))
' ask what pages need printing
On Error GoTo Canceled
strPages = InputBox( _
prompt:="What pages require printing?", _
Title:=(Space(45) & "ABCDF 1234"), _
Default:="1-4")
' loop through the print-write-print cycle
For lCounter = 0 To lCopiesToPrint - 1
' update the document variable
ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCounter
With Options
' .UpdateFieldsAtPrint = False
.UpdateLinksAtPrint = True
End With
ActiveDocument.Fields.Update
' print this numbered copy
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPages
Next lCounter
Canceled:
End Sub
Screenshot 2018-05-29 20.19.15.png One sticking point I have when I modified the code from ufrmPrintNumberedCopies is that it doesn't recognise the hyphens for the page range... Code:
If Not IsNumeric(Trim(Me.txtPages)) Then
MsgBox "The pages required should be a number", vbOKOnly
Me.txtPages.SetFocus
Me.txtPages.SelLength = Len(Me.txtPages)
form_validates_ok = False
Exit Function
End If
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with Case and Select case | brent chadwick | Word VBA | 34 | 10-18-2015 02:13 PM |
| Replace & case | Jennifer Murphy | Word | 1 | 02-11-2013 03:26 AM |
A macro that can insert FILENAME, sendkeys CTRL ALT T, paste clipboard, and nextline
|
kyjac85 | Word VBA | 13 | 09-20-2012 05:00 PM |
| Problem with the sendkeys in Win7 | vidyapakki | Excel Programming | 1 | 05-07-2012 11:10 PM |
From all UPPER CASE to Proper Case
|
davers | Word | 1 | 04-30-2009 12:41 PM |