Log in

View Full Version : Code to Change Apperance of Print Document



DaTrusHurtz
06-06-2008, 03:43 PM
Hi,

I don't really have any VBA knowledge and I need some help. I have a document which has a black background and white and grey text. However, when I print it, I'd like it to just have a normal white background and black text.

So basically, when someone pushes the print button, the VBA script would need to activate, change the background and font colors, print the document, then revert back to the way it was. How can this be done?

Thanks!

lucas
06-06-2008, 07:06 PM
I recorded this with the macro recorder but it works.....
Sub Macro1()
ActiveDocument.Background.Fill.Visible = msoFalse
ActiveDocument.PrintOut
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub

Crooz
06-09-2008, 01:27 AM
Hi DaTrusHurtz,
I tried the code that Lucas published but only get a blank sheet of paper printed. Try this:

Sub SwitchBackground()
Selection.WholeStory
Selection.Font.Color = wdColorBlack
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
ActiveDocument.PrintOut
Selection.Font.Color = wdColorWhite
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub

fumei
06-09-2008, 06:11 AM
1. be aware that when overwriting the print command (and it can be done) that:

FilePrint is the actual File > Print menu command.
FilePrintDefault is the Print button.

They are two different commands.

2. Do not use Selection. There is no need.

3. As both Steve and Crooz make assumptions regarding the font color, I will do so as well. With the exception that I set a variable to be whatever it is, then reset it BACK to that.


Dim CurrentFontColor
CurrentFontColor = ActiveDocument.Range.Font.Color

With ActiveDocument
.Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Range.Font.Color = wdColorAutomatic
' or maybe explicitly set for black

.PrintOut ' with whatever parameters you use
.Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Range.Font.Color = CurrentFontColor
End With


There is no need to set the .Fill (.Visible, and .Solid) unless you actually require it. In the code examples by Steve and Crooz they use these, but really, there is no need.

DaTrusHurtz
06-11-2008, 06:08 PM
Thanks for the help, much appreciated.

Unfortunately, I tried Crooz's file and it printed a blank page. I tried the code posted by Fumei, and that didn't work either, it printed as it normally would. Any ideas on what I could be doing wrong?

Thanks!