Watermark

L

Lee Kiwiflame

When a user presses a "Reprint" button, I want some code that:

- inserts a "Copy" watermark
- shows the print dialogue box so the user can select a printer
- then delete the watermark once the document has been printed.

Can anybody help me with some code for this? I'm not even sure where to
start. I did try recording the macro but I'm now stuck.

Thanks
 
J

Jay Freedman

When a user presses a "Reprint" button, I want some code that:

- inserts a "Copy" watermark
- shows the print dialogue box so the user can select a printer
- then delete the watermark once the document has been printed.

Can anybody help me with some code for this? I'm not even sure where to
start. I did try recording the macro but I'm now stuck.

Thanks

Don't try to create the watermark in code. It's gnarly and ugly, not to mention
slow. Instead, do this (note these instructions are for Word 2003 or earlier; if
you need them for Word 2007, post back):

- Open the template you're creating for this specific kind of document. (You
_are_ making a template, and not a document acting as a phony template,
I hope...)

- Use the watermark dialog to insert a COPY watermark. (No macro yet.)

- Open the header pane and select the watermark.

- Go to Insert > AutoText > AutoText. Enter the name CopyWatermark. Click the
Look In box and make sure it's set to your template, not Normal.dot or "All
active templates". Click the Add button and then OK.

- Back in the document, delete the watermark.

- Open the VBA editor and paste in this code:

Sub Reprint()
Dim oRg As Range
With ActiveDocument
Set oRg = .Sections(1).Headers(wdHeaderFooterPrimary).Range
.AttachedTemplate.AutoTextEntries("CopyWatermark").Insert _
Where:=oRg, RichText:=True
Dialogs(wdDialogFilePrint).Show
.Undo
End With
End Sub

- Create a Reprint button assigned to the Reprint macro.
 
N

Neil Humphries

Jay, can you expand on "a template, and not a document acting as a phony
template...". What are the differences and implications of using one or the
other?

I am using Word 2007 and would appreciate a 2007 version.

I suspect the gnarly part is resizing the watermark text to suit. Copying
the watermark from a template would let Word handle all the rotation and
resizing, correct?

Is it possible to create a series of watermark autotext entries all stored
in the same template? e.g. Draft, Not For Tender, For Coordination, Copy. I
could then let the user pick from a list box.

From my investigations, I haven't been able to uniquely identify a watermark
object. Watermarks appear to be in the header/footer, to be WordArt, and to
be part of the Shapes collection. Unfortunately so are some of the logos and
tag lines that are in the documents. Do you know how to be sure what you're
about to delete is a watermark? (The documents may have pre-existing
watermarks so I don't know the item name or the text that may be
encountered.) For the watermarks I create, I can name them for eazy selection
and deletion.
 
J

Jay Freedman

In line...

Neil said:
Jay, can you expand on "a template, and not a document acting as a
phony template...". What are the differences and implications of
using one or the other?

Well, a lot of people never use templates other than the Normal.dot (or
Normal.dotm in Word 2007) that's the base for "new blank documents". When
they need a new document that's similar to an old document, they just open
the old document and use Save As to make a copy that they then modify.
That's what I meant by "a document acting as a phony template".

A real template, with a filename extension of .dot (in 2007, .dotx or
..dotm), has a few characteristics that aren't shared by documents. One of
those is that AutoText entries can't be stored in documents, only in
templates.

In 2003 and earlier, the default location for AutoText was Normal.dot. In
2007, the default is Building Blocks.dotx. In either case, by changing a
setting in the dialog when you create the entry, you can direct it to a
different template. If these watermarks are going to be used only in
documents based on one template, they should be stored in that template; if
they're needed more generally, they should be in the default location (in
your case, Building Blocks.dotx).
I am using Word 2007 and would appreciate a 2007 version.

I'll get back to you shortly -- after I've had a chance to write the macro
and test that I got it right.
I suspect the gnarly part is resizing the watermark text to suit.
Copying the watermark from a template would let Word handle all the
rotation and resizing, correct?

No, the idea is that you create, size, and otherwise format the watermark
only once, and store the result. That can be reused ad infinitum with no
further manipulation.
Is it possible to create a series of watermark autotext entries all
stored in the same template? e.g. Draft, Not For Tender, For
Coordination, Copy. I could then let the user pick from a list box.

Yes, all you need to do is give each entry a unique name.
From my investigations, I haven't been able to uniquely identify a
watermark object. Watermarks appear to be in the header/footer, to be
WordArt, and to be part of the Shapes collection. Unfortunately so
are some of the logos and tag lines that are in the documents. Do you
know how to be sure what you're about to delete is a watermark? (The
documents may have pre-existing watermarks so I don't know the item
name or the text that may be encountered.) For the watermarks I
create, I can name them for eazy selection and deletion.

The scheme you outlined before was that the watermark is present in the
document only as long as it takes to print. That's why the macro I showed
contains ".Undo" near the end -- the effect of that statement is to remove
the AutoText entry that was added at the beginning of the macro, just as if
you had clicked the Undo button. The watermark object in the document
doesn't have to be named or tagged in order to remove it. There's also no
confusion between the watermark and any pre-existing logo or other things in
the document; the "undo stack" knows what item was added last and how to
remove it.

The one possible concern, which you would have to test on your documents, is
whether the watermark causes the logo to be pushed to an incorrect position.
If so, you'll have to format the watermark (and possibly also the logo) to
allow overlap.
 
N

Neil Humphries

Great information. I'll be modifying my code to use stored AutoText entries.

I think on the last question, you missed that I am not Lee (the original
questioner). In my case I don't have an undo stack to rely on. So, to pose
the question again:

From my investigations, I haven't been able to uniquely identify a watermark
object. Watermarks appear to be in the header/footer, to be WordArt, and to
be part of the Shapes collection. Unfortunately so are some of the logos and
tag lines that are in the documents. Do you know how to be sure what you're
about to delete is a watermark? (The documents may have pre-existing
watermarks so I don't know the item name or the text that may be
encountered.) For the watermarks I
create, I can name them for easy selection and deletion.
 
J

Jay Freedman

Hi Neil,

Yes, I missed that you weren't Lee asking about the original situation and
the macro I suggested.

You're correct that a watermark is a WordArt object anchored in a header. In
that respect it's no different from any other WordArt object anchored in a
header. The only thing that appears to distinguish it is the name that Word
assigns to it when you use the Watermark dialog. When I record the insertion
of a watermark, it names the Shape as

Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"

If you're writing your own code to insert and remove pseudo-watermarks, you
can avoid touching logos or tag lines by assigning a similarly unique name
to the pseudo-watermarks.
 
L

Lee Kiwiflame

Thanks Jay. I didn't even think about using autotext and then using code to
insert the autotext.

All the docs I want the watermark added to are templates (e.g. .dot files).
However, I have about 20 templates I need to add this to so would have to add
the autotext to each template.

I will open each template and use the Tools > Templates and Add-Ins >
Organiser, to add the autotext.

Your help is appreciated.

Regards
Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top