Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Crashes VB Code to ActiveSheet.PrintOut

Status
Not open for further replies.

hext2003

Technical User
Oct 9, 2006
119
US
This is my code. If I print only one at a time I'm Fine. If I print a range from 1 to 10 and step through the code it works fine. If I print a range 1 to 10 and just let the code run, excel crashes.

I have to print 2200 of these. i don't want to have to step through all of them. This worked just fine last year. I didn't change any code between last year and this year.

What's up with this??? Please Help Please!!! I think it's the ActiveSheet.PrintOut that crashes it. But I don't understand why... did an SP2 or SP3 break it???

My Code...

Sub PrintForms()
Dim StartRow As Integer
Dim EndRow As Integer
Dim Msg As String
Dim i As Integer
Dim PrtPg5 As Boolean

Dim XI As Range
Set XI = Range("Form!B422")

Dim XX As Range
Set XX = Range("Form!B362")

Dim XH As Range
Set XH = Range("Form!B399")

Dim acct

PrtPg5 = True
Sheets("Form").Activate
StartRow = Range("StartRow")
EndRow = Range("EndRow")


If StartRow > EndRow Then
Msg = "ERROR" & vbCrLf & "The starting row must be less than the ending row!"
MsgBox Msg, vbCritical, APPNAME
End If

For i = StartRow To EndRow

Range("RowIndex") = i

'For Footer
acct = Worksheets("Form").Range("A308").Value
Worksheets("Form").PageSetup.CenterFooter = "&""OCR A Extended,Regular""&12" & acct

'Checks if need page 5 printed
If XI > 0 Or XX > 0 Or XH > 0 Then
PrtPg5 = True
ActiveSheet.PageSetup.PrintArea = "Print5"
Else
PrtPg5 = False
ActiveSheet.PageSetup.PrintArea = "Print4"
End If


If Range("Preview") Then
ActiveSheet.PrintPreview
Else
ActiveSheet.PrintOut
End If


Next i
End Sub
 
Hi,

Please post VBA code questions in Forum707. We will not discuss VBA questions here.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top