Need to use Print Preview while using BeforePrint Event

samsilverman

Board Regular
Joined
Nov 9, 2009
Messages
166
I am using Excel 2007

I have this code in my ThisWorkbook Module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets("Sheet1").Range("B2,B5,B8,B13").Font.ColorIndex = 2
End Sub

I have this code in each Worksheet Module I want to use it for:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("B2,B5,B8,B13").Font.ColorIndex = xlAutomatic
End Sub

Basically I am change the range to white font before printing so it doesn't show up. Then after the print, a click anywhere on the sheet makes the info in the range show up again.

The problem is I get an error box when I want to print preview. Is there a way around this?

The error box says: "Compile error: Ambiguous name detected: Workbook_BeforePrint"

Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

samsilverman

Board Regular
Joined
Nov 9, 2009
Messages
166
No. the only other code I have in the workbook module is:

Private Sub Workbook_Open()
Worksheets("ACCOUNT").Range("B1").Value = "LAST SAVED:" & " " & Date & " " & Time
End Sub
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
That shouldn't affect it. But you can only have one Workbook_BeforePrint per workbook. Are you sure you don't have another one?
 

samsilverman

Board Regular
Joined
Nov 9, 2009
Messages
166

ADVERTISEMENT

Unless it is somewhere other than my ThisWorkbook module, those two are the only codes I can see.

btw, it lets me print preview after I close the error box. I just don't like the error box. :)
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Sorry but I don't understand why you are getting that error.
 

samsilverman

Board Regular
Joined
Nov 9, 2009
Messages
166
i figured it out. I was trying to apply the code to 2 worksheets in the workbook. I guess that is technically 2 separate BeforePrint events, hunh?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,911
Messages
5,638,947
Members
417,060
Latest member
wcbobb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top