Help With code

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
 
C

Chip Pearson

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
 
R

RB Smissaert

Maybe this will do it (un-tested):

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

RBS
 
G

Greg B

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
 
B

Bob Phillips

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)
 
D

Don Guillett

try
SixDigit = InputBox("How many print-outs do you want?", " ", "2")
if sixdigit=false then exit sub
 
D

Doug Glancy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

inputbox syntax location 3
Printing Macro 4
Print Code Help 5
Command Button 6
Printing Macro 1
Preventing printing 3
Code not printing to color printer 4
Need VBA help 3

Top