Hello 6StringJazzer,
thanks for the pointer, that helped. I had to put in a bit of stuff additionally to catch the difference between the original print and the print of the individual work-sheets as otherwise every print would have been cancelled.
It looks like that as total:
Dim WS_Number As Long
Dim CurrentSheet As Long
Dim BolIndividualPrint As Boolean
Dim BolPrintDone As Boolean
Private Sub SheetPrint()
Dim WS As Worksheet
For Each WS In Worksheets
If CurrentSheet = WS_Number - 1 Then
BolIndividualPrint = False
BolPrintDone = True
End If
WS.PrintOut
CurrentSheet = CurrentSheet + 1
Next WS
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not BolIndividualPrint Then
Cancel = True
If Not BolPrintDone Then
WS_Number = Worksheets.Count
CurrentSheet = 0
BolIndividualPrint = True
Call SheetPrint
Else
BolPrintDone = False
End If
End If
End Sub
As additional icing on the cake that code needs to be placed into a generated file which is only used for the printout. For that I went for the programmatic editing of that generated file:
Sub AddSht_AddCode()
Dim wb As Workbook
Dim xPro As VBIDE.VBProject
Dim xCom As VBIDE.VBComponent
Dim xMod As VBIDE.CodeModule
Dim xLine As Long
With wb
Set xPro = .VBProject
Set xCom = xPro.VBComponents("ThisWorkbook")
Set xMod = xCom.CodeModule
With xMod
xLine = .CountOfLines + 1
.InsertLines xLine, "Dim WS_Number As Long"
xLine = xLine + 1
<...>
.InsertLines xLine, "Private Sub SheetPrint()"
xLine = xLine + 1
.InsertLines xLine, " Dim WS As Worksheet"
xLine = xLine + 1
<...>
xLine = .CreateEventProc("BeforePrint", "Workbook")
xLine = xLine + 1
.InsertLines xLine, " If Not BolIndividualPrint Then"
xLine = xLine + 1
<...>
End With
End With
ActiveWorkbook.Save
end sub
So thanks a lot for the pointer.
Cheers,
Moadll
Bookmarks