PDA

View Full Version : Something wrong with my macro



Zack
04-21-2012, 08:53 AM
lCopiesToPrint = InputBox( _
Prompt:="Number of copies?", _
Title:="copies", _
Default:="1")

For lCounter = 0 To lCopiesToPrint - 1

ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCounter


ActiveDocument.PrintOut Copies:=1
Next lCounter

End Sub


I am trying to make a macro for printing asking how many copies I need, but this one prints all copies as separated print jobs..I thought of printing all the copies as one job..

Tinbendr
04-21-2012, 09:53 AM
lCopiesToPrint = InputBox( _
Prompt:="Number of copies?", _
Title:="copies", _
Default:="1")

ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCopiesToPrint

ActiveDocument.PrintOut Copies:=lCopiesToPrint
End Sub

Zack
04-21-2012, 10:09 AM
It doesn't work quite right.

When I click cancel it still prints the job..

Zack
04-21-2012, 10:26 AM
So basically I would need it to stop if I press the cancel button.

Tinbendr
04-21-2012, 10:35 AM
Sorry, I though you only wanted to fix the printout problem.

Sub test()
Dim lCopiesToPrint As Variant

lCopiesToPrint = InputBox( _
Prompt:="Number of copies?", _
Title:="copies", _
Default:="1")

If lCopiesToPrint > 0 Then

ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCopiesToPrint

ActiveDocument.PrintOut Copies:=lCopiesToPrint
End If

End Sub

Zack
04-21-2012, 10:43 AM
It still prints

Zack
04-21-2012, 10:46 AM
Sorry, I though you only wanted to fix the printout problem.

Sub test()
Dim lCopiesToPrint As Variant

lCopiesToPrint = InputBox( _
Prompt:="Number of copies?", _
Title:="copies", _
Default:="1")

If lCopiesToPrint > 0 Then

ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCopiesToPrint

ActiveDocument.PrintOut Copies:=lCopiesToPrint
End If

End Sub



It works now I just copied the line a little below

ActiveDocument.Variables("CopyNum") = _
lCopyNumFrom + lCopiesToPrint

If lCopiesToPrint > 0 Then

Zack
04-21-2012, 10:51 AM
lol, still doesn't work..

Zack
04-21-2012, 10:59 AM
I tried relocating If > 0 Then line, but it didn't help..

Tinbendr
04-21-2012, 02:13 PM
eck! Sorry, my bad.

If Val(lCopiesToPrint) > 0 Then and probably for good measure.

ActiveDocument.PrintOut Copies:=Val(lCopiesToPrint)

Zack
04-21-2012, 02:43 PM
Works. Ty.