Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Change Print Command or add a new print command

I have a a macro button on my excel sheet that will clean up the gray areas
on my sheet. I would like to know if it is possible to do this if someone
clicks on the print icon instead of having this function?

Any ideas?

Thank you,

Daniel Young
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Change Print Command or add a new print command

Hi Daniel,

When I hit the print button it still printed without my area cleaning.
Here
is the code I used:


As your code does not issue any print command, I suspect that you have
inadvertently turned off application events and, consequently, your code is
not running.

To ensure that the Application.Events setting is restored, run the
following:

'============
Sub AAA
Application.EnableEvents = True
End sub
'<<============

I have added a print instruction to your code and reduced the two loops to a
single loop. I also added an instruction to limit the code to the Reort
sheet, so that other sheets can print normally.

Try:

'==============
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim rng As Range, c As Range

If ActiveSheet.Name < "Report" Then Exit Sub

On Error GoTo ws_exit

Application.EnableEvents = False
Cancel = True

Worksheets("Report").Unprotect

Set rng = Selection

For Each c In rng
If c.Interior.ColorIndex = 15 Then
c.Interior.ColorIndex = 2
ElseIf c.Font.ColorIndex = 5 Then
c.Font.ColorIndex = 2
End If
Next c

Worksheets("Report").Protect

ActiveSheet.PrintOut

ws_exit:
Application.EnableEvents = True

End Sub
''<<==============


---
Regards,
Norman


"Daniel R. Young" wrote in message
...
When I hit the print button it still printed without my area cleaning.
Here
is the code I used:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
Cancel = True

Worksheets("Report").Unprotect
Dim rng As Range, c As Range
Set rng = Selection
For Each c In rng
If c.Interior.ColorIndex = 15 Then
c.Interior.ColorIndex = 2
End If
Next c
For Each c In rng
If c.Font.ColorIndex = 5 Then
c.Font.ColorIndex = 2
End If
Next c

Worksheets("Report").Protect
ws_exit:

Application.EnableEvents = True
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print Command M&M[_2_] Excel Discussion (Misc queries) 1 July 27th 07 11:22 AM
how to print a sheet by command ghost Excel Discussion (Misc queries) 4 May 1st 07 05:33 PM
How to format the extension less file to print with Dos's Print Command Badshah Excel Discussion (Misc queries) 0 November 28th 06 12:44 PM
Print Command Durga Excel Discussion (Misc queries) 0 October 27th 05 12:02 AM
Print command box Meghan Excel Discussion (Misc queries) 1 June 16th 05 12:34 AM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"