Hello everybody!
As described in the title, my issue is a print macro that loops infinitely in Excel 2007 (weirdly not in '03 or '10)
File: The excel file I'm working on has one sheet with the list of contents and 200 sheets with data.
I use Excel 2003 to work on it, but the final file needs to work on 2007 as well.
Task: Checkboxes for each item in the list of contents to select any amount of data sheets to be printed.
Solution: When a checkbox is checked, it adds the value "PRINT" to a specific cell (G1), or deletes the value when unchecked.
A Button called Print then prints each sheet with the Value "PRINT" in cell G1
Application.ScreenUpdating = False
On Error GoTo N20
Worksheets(1).Select
GoTo N1
N10:
Worksheets(ActiveSheet.Index + 1).Activate
N1:
If ActiveSheet.Range("G1").Value = "PRINT" Then
ActiveWindow.SelectedSheets.PrintOut 1, 1, 1, False
If Err.Number <> 0 Then
Worksheets(1).Activate
Else
End If
GoTo N10
Else: End If
GoTo N10
N20:
Application.ScreenUpdating = True
Worksheets(1).Activate
Problem: This works like a charm in Excel 2003 and 2010. In 2007 whatsoever the macro loops infinitely and reprints the selected pages.
(If you want to test this I sugest using the Microsoft XPS Printer, since it stopps everything when you press cancel)
I think the correct path of solving this would be by limiting the loops to the amount of selected pages(LBound/UBound?), but I have no Idea how to include this.
I can count the amount of selected pages with this macro:
Dim ws As Worksheet
Dim c As Long
For Each ws In Worksheets
If ws.Range("G1").Value = "PRINT" Then
c = c + 1
End If
Next ws
Debug.Print c
Thanks already for any help and suggestions!
Bookmarks