Printing within macro

natan

New member
Local time
Today, 13:49
Joined
Sep 10, 2008
Messages
1
hi everyone,

I am having trouble with the code below. After the first loop (i.e, after the first iteration) i get a message box saying "Code execution has been interrupted" with buttons Continue, Debug, End, and Help below the message. Hitting continue makes it resume the loop but that defeats the whole purpose as I have to do this for every record.

I suspect this has something to do with the PrintOut method but can't figure out what is it. The code is interrupted after the print and when I hit Debug it highlights the "Loop" line. What's going on here?

Any suggestions would be appreciated.

-Natan



Sub PrintCalcSheets()
Dim counter As Integer
counter = 1
Do While counter < 4
Sheets("Benefit calc").Cells(2, 15).Value = counter
Call Macro3
Sheets("Benefit calc").Select
Selection.Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
counter = counter + 1
Loop
End Sub
 
Printing a page takes a bit of time so while the OS is still trying to print your macro is moving on and you get this error appearing. Between where you print and increment your counter try adding doevents

Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
doevents
counter = counter + 1
 

Users who are viewing this thread

Back
Top Bottom