Help With code

  • Thread starter Thread starter Greg B
  • Start date Start date
G

Greg B

I am having a bit of trouble with this code, it is causing a runtime error
1004, when the cancel button is hit on the input box. How can I correct the
code below?

Dim SixDigit As String

SixDigit = InputBox("How many print-outs do you want?", " ", "2")

ActiveWindow.SelectedSheets.PrintOut Copies:=SixDigit, Collate:=True

End Sub
Thanks

Greg
 
Try

SixDigit = InputBox("How many print-outs do you want?", " ", "2")
If IsNumeric(SixDigit) Then
ActiveWindow.SelectedSheets.PrintOut Copies:=SixDigit,
Collate:=True
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Maybe this will do it (un-tested):

ActiveWindow.SelectedSheets.PrintOut Copies:=Val(Trim(SixDigit)),
Collate:=True

RBS
 
Thanks for that

Greg
Chip Pearson said:
Try

SixDigit = InputBox("How many print-outs do you want?", " ", "2")
If IsNumeric(SixDigit) Then
ActiveWindow.SelectedSheets.PrintOut Copies:=SixDigit, Collate:=True
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Dim SixDigit As String

SixDigit = InputBox("How many print-outs do you want?", " ", "2")

If SixDigit <> "" Then
ActiveWindow.SelectedSheets.PrintOut Copies:=SixDigit, Collate:=True
End If



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
try
SixDigit = InputBox("How many print-outs do you want?", " ", "2")
if sixdigit=false then exit sub
 
Sub test()

Greg,

I used the more complex type of inputbox which allows you to specify input
type (in this case "1" allows only numeric input).

Dim SixDigit As Long
SixDigit = Application.InputBox("How many print-outs do you want?", Type:=1,
Default:=2)
If SixDigit > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=SixDigit, Collate:=True
End If

End Sub
 
Back
Top