View Single Post
  #2   Report Post  
Posted to microsoft.public.word.pagelayout
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Add Printer Name to Footer

Because there is no field in Word that returns the name of the current
printer, you'll need a macro to insert the date and printer name just before
printing.

One way to do this is to write a macro in each test template, and name the
macro FilePrint. Then when you use the File Print menu item or press
Ctrl+P, the macro runs instead of the built-in command. You'd need a second
macro named FilePrintDefault to intercept the print button on the toolbar.

You said your test templates are simple documents -- I assume that means
they're *.doc files. Although you can put a macro into a document, that's a
seriously bad idea because Word's security mechanism sees that as a probable
virus attack. If you resave your test "templates" as real template (*.dot)
files, and store them in the Templates folder, then you can tell Word to
trust macros in the templates (that's on the second tab of the Tools Macro
Security dialog).


A better idea is to put the macro into a module in a template that you store
in Word's Startup folder, so it's loaded and available every time you start
Word. (The Startup folder is usually at %appdata%\Microsoft\Word\STARTUP,
but check the Tools Options File Locations dialog to be sure.) In the
same template, also add a toolbar button and/or menu item to run the macro
(http://www.word.mvps.org/FAQs/Custom...ToToolbar.htm),
leaving the built-in commands untouched.

The macro code can be something like this:

Sub AddFooterAndPrint()
With ActiveDocument
' Put the date and the name of the
' current printer in the main footer.
' This will replace anything that was there before.
.Sections(1).Footers(wdHeaderFooterPrimary) _
.Range.Text = Format(Now, "MMMM dd, yyyy") & _
vbTab & Application.ActivePrinter

' Send the document to the printer.
.PrintOut Background:=False

' Remove the change. If the document
' didn't need to be saved before, it won't
' need to be saved now.
.Undo
End With
End Sub

You can play with the formatting of the footer to get whatever appearance
you want. Things get more complicated if the documents have more than one
section and the footers are disconnected (not "Same As Previous").

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

wrote:
Hello,

I work for a company that make printable materials for laser, inkjet,
solvent inkjet, and other kinds of printers. Several of our test
templates are simple Word documents with a particular pattern on
them. It becomes very tedious to keep track of them as we have to
write the date and printer name on each sheet (sometimes in the 100s).

Is there a way to insert the printer name automatically when I click
the print button? I have found two articles on using either
DocumentBeforePrint and a VBScript for inserting the printer name, but
I could not make either work.

I'd prefer to have the process remain part of the individual file and
not have to edit my normal.dot if possible.

Could someone provide me with some detailed instructions on how to
accomplish this? I'm not that good with VB, but I can follow
instructions.

Thanks in advance,