Workbook BeforePrint Cancel As Boolean

Workbook_BeforePrint occurs when any print command is used—menu, toolbar, keyboard, or macro. Cancel set to True prevents the workbook from being printed.

The following code tracks each time a sheet is printed. It logs the date, time, username, and the sheet printed in a hidden print log (see Figure 8.4):

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim LastRow As Long

Dim PrintLog As Worksheet

Set PrintLog = Worksheets("PrintLog")

LastRow = PrintLog.Range("A65536").End(xlUp).Row + 1

With PrintLog

.Cells(LastRow, 1) .Cells(LastRow, 2) .Cells(LastRow, 3) End With End Sub

Value = Application.UserName Value = ActiveSheet.Name

Figure 8.4

The BeforePrint event can be used to keep a hidden print log in a workbook.

0 0

Post a comment