J
John
A person sent me this code. I am not sure where
specifically to place it in my Excel spreadsheet to make
it work as I am not sure where the 'Thisworkbook' module
is. Please advise. His instructions:
If you press the Print button or use File>Print
the event below will check the ActiveSheet name and run
the code.
This example will run if the ActiveSheet name = "Sheet1"
1) It will hide row 10:15
2) Print
3) Unhide row 10:15
You must place this event in the Thisworkbook module
1) Copy the code
2) Right click on the Excel icon next to File in the menu
bar
3) Choose view code
4) Paste the code
5) Alt-Q to go back to Excel
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Rows("10:15").EntireRow.Hidden = True
.PrintOut
.Rows("10:15").EntireRow.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
specifically to place it in my Excel spreadsheet to make
it work as I am not sure where the 'Thisworkbook' module
is. Please advise. His instructions:
If you press the Print button or use File>Print
the event below will check the ActiveSheet name and run
the code.
This example will run if the ActiveSheet name = "Sheet1"
1) It will hide row 10:15
2) Print
3) Unhide row 10:15
You must place this event in the Thisworkbook module
1) Copy the code
2) Right click on the Excel icon next to File in the menu
bar
3) Choose view code
4) Paste the code
5) Alt-Q to go back to Excel
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Rows("10:15").EntireRow.Hidden = True
.PrintOut
.Rows("10:15").EntireRow.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub