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
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

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,651
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
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,651
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,099,547
Messages
5,469,350
Members
406,647
Latest member
ssinovec

This Week's Hot Topics

Top