PDA

View Full Version : Turn off Print drawings created in Word printing options



RandiJ
07-03-2012, 08:32 AM
I have a template that will be shared among several people and I have a text box with instructions on how to fill out the template that I don't want to print. I know I can go to the display options to turn off the "Print drawings created in Word" option but is there a way to automate this task in the event others don't know to turn off the option.

Thank you.:hi:

macropod
07-03-2012, 09:07 PM
You can use a filed coded as:
{IF{PRINTDATE \@ yyyyMMddHHmm}= {DATE \@ yyyyMMddHHmm} "" "Your instructions go here."}

Note: The field brace pairs (ie '{ }') for the above example are created in the body of the document via Ctrl-F9 (Cmd-F9 on a Mac) - you can't simply type them or copy & paste them from this message.

Pressing F9 or print preview restores the display. However, since the PRINTDATE field doesn't support seconds, you might have to wait up to a minute before you can restore the display.

RandiJ
07-12-2012, 07:16 AM
Thank you for responding. The field was giving me problems so I decided to try a macro that will delete the text box before printing by adding an application event. However, I cannot figure out how to get it to work. I saved my document as a macro enabled template and then proceeded to add the event:

Option Explicit

Public WithEvents oApp As Word.Application

Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Dim shp As Shape
For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then shp.Delete
Next shp

End Sub

Private Sub oApp_Quit()

End Sub

I closed out the VB Editor and then tried to print the document but it still has the text box.

Any suggestions for a solution?

Thank you.

Frosty
07-12-2012, 09:32 AM
Is that all the code you have to do the event? Because that isn't enough.

You need to:
1. Load the event handler (probably during Document Open or Document New events within the ThisDocument object).

2. Create an event handler class.

So you would need something like the following code in your ThisDocument class module:

Option Explicit
Private m_appWord As ThisApplication
Private Sub Document_Open()
EventHandler_Load
End Sub
Private Sub Document_New()
EventHandler_Load
End Sub
Public Sub EventHandler_Load()
Set m_appWord = New ThisApplication
End Sub
And then you need to create a new class module, and name it "ThisApplication" (the name doesn't really matter, but that is what the code above refers to).
And within your class module, you would need the following:

Option Explicit
Private WithEvents oApp As Word.Application
Private Sub Class_Initialize()
Set oApp = Word.Application
End Sub
As well as your oApp_DocumentBeforePrint routine above.

I would probably comment out your shape delete stuff, and simply use Debug.Print "Hello" or MsgBox "Hello" to verify that your event is actually firing.

Hope this helps.

If this is overwhelming, maybe you should try Paul's field suggestion a little more. Having trouble getting a field in Word to work and then jumping into Event programming is quite a leap ;)

Frosty
07-12-2012, 09:37 AM
Just an additional thought-- my post helps point you toward using word events, however, I don't think that's probably the best solution for the problem you described.

You have a textbox which gives information to people which you don't want to have print... off the top of my head
1. You could put the contents of the text box into a message box which pops up whenever the document is opened
2. You could automatically turn off the print graphics whenever the document is opened, hold the previous value... and then turn it back on when the document is closed (using the built-in ThisDocument events).
3. Type your text in a hidden font, which won't print, but would show up if your end-users are showing paragraph marks.

I'm sure there are other approaches which don't require a custom event handler...

RandiJ
07-19-2012, 07:31 AM
Thank you. I went back and was able to get the field code to work. However, I cannot get my instructions to re-display after I print even when pressing F9 after a few minutes. Is there a way to get the instructions to re-display after printing?

Thank you.

macropod
07-19-2012, 03:13 PM
Before pressing F9, you must ensure the field code's range is selected. Try Ctrl-A, then F9.