I am looking for help creating a simple Macro for Word 2013 that checks if the user is printing more than 1 copy and cancels the print job.
Some solutions like:
Obviously forcing 1 automatically would be better, but likely more complicated. I figure just a prompt + cancel print job would be easiest and then user can go back and change to print 1 copy.
Reasoning:
I have a macro that prints documents with an incrementing number, but if you select say Print 2 Copies, then the Macro ask's "How many copies" and you say 2, you get 4 documents.
2x Doc # 1
2x Doc # 2
I need to users to ALWAYS select 1 copy in the Word Print Screen then select the # of copies in the Macro Prompt Box.
How can I enforce this?
So my solution involved a flag in ActiveDocument.PrintOut
which specifies copies Copies:=1
. This went into the macro that Prints the documents and inside the DocumentBeforePrint
I use Cancel = True
.
This allows the user to select whatever number they want in Word and it gets funneled to Cancel = True
, then the Macro ask's "how many copies would you like" and prints X amount of copies incrementing the number each time. Somehow before, even the Macro would take the number of copies set in word and apply it in the macro, so I'd get duplicates of the same serial numbered document which was not what I wanted.
I see users putting the same number in both Word and in Macro MsgBox, but really they can just put whatever in Word and it is Only the Macro MsgBox that matters.
The final two code snippets look like this:
Public WithEvents App As Word.Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
'Cancel = True = Don't bother printing whatever was selected in Word Print Page
Cancel = True
Call FilePrint
End Sub
Module:
Sub FilePrint()
Dim i As Long, j As Long
With ActiveDocument
j = CLng(InputBox("How many copies to print?", "Print Copies"))
For i = 1 To j
With .CustomDocumentProperties("Counter")
.Value = .Value + 1
End With
.Fields.Update
' Added Copies:=1 to force no Duplicates!
ActiveDocument.PrintOut Copies:=1
Next
.Save
End With
End Sub