Not sure where 'Thisworkbook' module is

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
 
V

Vasant Nanavati

Click on the inner, smaller Excel icon at the top left of your window and
click on View Code. This will take you to the ThisWorkbook module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top