Need to use Print Preview while using BeforePrint Event

samsilverman

Board Regular
Joined
Nov 9, 2009
Messages
176
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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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
 
Upvote 0
That shouldn't affect it. But you can only have one Workbook_BeforePrint per workbook. Are you sure you don't have another one?
 
Upvote 0
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. :)
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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
Back
Top