I 've made a VBA prog that generates a print preview from 3 different sheets. it selects the not empty sheets and gives the preview.
When i want to close the preview excel bails out with an error, unless the preview shows the first sheet. Already tried to change the order in the selection, without any effect.
Does anybody know why this happens?
this is my code so far:
Private Sub cmdAfdrukkenLijsten_Click()
Dim intRij As Integer
'adding some extra cells before printing (if sheets aren't empty)
If Worksheets("luchtgroepen").Range("B5") <> "" Then
Call legende
Worksheets("luchtgroepen").Select
intRij = Worksheets("luchtgroepen").Range("A1").Value
Worksheets("luchtgroepen").Range("A" & intRij).Select
ActiveSheet.Paste
Range("A" & intRij, "B" & intRij).Font.Bold = True
End If
If Worksheets("specifiek klant").Range("B3") <> "" Then
Call legende
Worksheets("specifiek klant").Select
intRij = Worksheets("specifiek klant").Range("A1").Value
Worksheets("specifiek klant").Range("A" & intRij).Select
ActiveSheet.Paste
Range("A" & intRij, "B" & intRij).Font.Bold = True
End If
'determening print-area
Worksheets("overzichtsblad").Activate
intRij = Worksheets("overzichtsblad").Range("A1").Value + 2
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$" & intRij
'selecting non-empty sheets foor preview
If Sheets("specifiek klant").Range("B3") <> "" Then
If Sheets("luchtgroepen").Range("B5") <> "" Then
Sheets(Array("overzichtsblad", "specifiek klant", "luchtgroepen")).Select
Else
Sheets(Array("overzichtsblad", "specifiek klant")).Select
End If
Else
If Sheets("luchtgroepen").Range("B5") <> "" Then
Sheets(Array("overzichtsblad", "luchtgroepen")).Select
Else
MsgBox "Geef eerst de onderdelen van de installatie op." & vbCrLf & _
"Voor uitleg klik op de Info knop", vbOKOnly + vbExclamation, "Fout"
Exit Sub
End If
End If
ActiveWindow.SelectedSheets.PrintPreview
End Sub
Bookmarks