Adding watermark to the document

A

Ankesh Mehta

I recorded a macro to insert watermark in a document. The document has
multiple sections and different first page and primary headers.

Word adds the watermark perfectly but when I run the macro the
watermark is not available on many pages and also it is not centered on
the page.

Has anybody else faced this problem too? Any comments will be
appreciated

Thanks,
 
C

Charles Kenyon

This is one of many problems with using recorded macros.
http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm.

Watermarks are a part of the header/footer structure. Each of you sections
apparently has two headers and footers. You will need to cycle through the
sections and the headers/footers (using ranges, not the selection object)
and insert your watermark in each one.

The following code cycles through storyranges to update fields. It may give
you a start.
Sub FieldsUpdateAllStory()
' All Story Field Updater
' Written by Charles Kyle Kenyon 9 December 2004
' repaired with help from Jezebel 10 December 2004, 28 November 2005
' Note, if used in protected form this will reset
' formfields to their defaults
Dim oStory As Range
On Error Resume Next
For Each oStory In ActiveDocument.StoryRanges
Do
oStory.Fields.Update
Set oStory = oStory.NextStoryRange
Loop Until oStory Is Nothing
Next
End Sub

The following code inserts a field in the primary header of section 1.

Sub InsertStyleRef()
' Macro written by Charles Kenyon 24 January 2002
' From code posted by David Lett
' Inserts StyleRef field in primary header replacing first paragraph
' - including paragraph mark!
'
ActiveDocument.Fields.Add _
Range:=Selection.Sections(1).Headers(wdHeaderFooterPrimary). _
Range.Paragraphs(1).Range, _
Type:=wdFieldStyleRef, _
Text:="witness", _
PreserveFormatting:=False
End Sub

Hope these are of some help in getting you started. I would suggest
attempting it and then writing back with the code you have if you can't get
it to work.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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