cant read memory crash when printing
Think I have solved the problem :-
I put a pause in the code prior to printing. Everything then worked ok.
Seemed to be excel started printing before excel had finished creating the
page to print and this caused the cant read from memory crash.
Strange but not going to argue, cause it works so far, touch wood.
Anthony
"Anthony" wrote in message
...
I am writing VBA on a works computer, so I dont have admin rights etc on
the machine, so any solutions need to take that into account. The workbook
is under 1mb even when populated and the code runs in single step mode and
9 times out of 10 when run normally, but from time to time excel crashes
with a cant ready memory error at the point of me printing.
I have re-coded a whole section of the printing routine to stop the
execution of events loading info prior to print and that solved alot of
the crashes and it now works 9 times out of 10. I have also ensured every
userform is unloaded after use and there are no duplicate unloads.
The print code is very simple for the section excel falls over in. It
tests to see if the user has selected an entry from a list box, hides the
listbox, loads page with info, selects the page, prints, tests to see if
the user wants a letter, selects letter page, prints letter the no. of
times set on user form.
I am using excel 2000.
code:-
Private Sub cbSelected_Click()
Dim lItem As Long
ufAnimal_List.Hide
For lItem = 0 To Me.lbAnimal_Selection.ListCount - 1
If Me.lbAnimal_Selection.Selected(lItem) = True Then
Worksheets("animal Card").Range("B16").Value =
Worksheets("workpage").Range("BV" & _
(7 + lItem)).Value
Worksheets("animal Card").Range("B23").Value =
Worksheets("workpage").Range("BW" & _
(7 + lItem)).Value
Worksheets("animal Card").Range("B23").Value =
Worksheets("animal Card").Range("B23").Value + _
". " + Worksheets("workpage").Range("CF" &
Search_Line("CE", _
Worksheets("workpage").Range("CG5").Value,
_
Worksheets("workpage").Range("BS" & (7 +
lItem)).Value)).Value
Worksheets("Animal Card").Select
'ActiveSheet.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=1
'If print letter option selected then print letter
If (Worksheets("workpage").Range("G61").Value = True) Then
Worksheets("Animal Letter").Select
'Print no. copies of letter one for customer and other for
walk log
ActiveWindow.SelectedSheets.PrintOut
Copies:=Val(Me.tbCopies.Text)
End If
Me.lbAnimal_Selection.Selected(lItem) = False
End If
Next lItem
End Sub
Any ideas on why it would be crashing when printing?
Anthony
|