Microsoft Word - User gets an error when they choose 'cancel' and don't answer question generated by macro

Asked By Charlene Quinlan on 18-Oct-12 04:56 PM
I have the following code:
Private Sub CommandButton5_Click()
Dim Copies As String
Copies = InputBox("Enter number of copies to print (Word will use your default printer)")
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Copies:=Copies, Pages:="17-19", PageType:=w
End Sub

If the user enters a digit it works. If they choose cancel, they get an error and telling them the value is out of range and the debugger starts.

Is there an easy fix?
Robbe Morris replied to Charlene Quinlan on 18-Oct-12 05:00 PM
Yes

Check to see if Copies is null or an empty string.  If so, exit the sub before you print it.
Charlene Quinlan replied to Robbe Morris on 09-Nov-12 02:03 PM
Thank you for your help.