Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a watermark macro for Word 2007

Status
Not open for further replies.

renigar

Technical User
Jan 25, 2002
111
US
I been reading various post on the web and hear mention of a macro that prompts the user for the watermark text and page range to apply the watermark to (an important feature). I don't use Word much but it seems to me this feature is much trickier to use then it should be. I don't expect anyone to write a macro, but if you know of one that exist and can point me to it I would be very grateful.
Renigar
 
A watermark that is applied to a page range? I thought a watermark is applied to the whole document.

 
The default is to apply the watermark to every page in the document. Word has a way to apply watermarks to selected pages. The process is described as divide the document into sections using section breaks (not page breaks) and unlink the headers, then apply the watermark. I may not have this exactly correct. I have managed to do it a couple of times, but not consistently. That's why I'm looking for a macro. Microsoft should of had a right click, apply watermark in the context menu.
 



the watermark is applied in the Section Header. Try turning on you macro recorder and performing that.

Post back with your recorded code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
prompts the user for the watermark text and page range to apply the watermark to (an important feature)."

Yes watermarks are header (thus Section) driven, but that most certainly is nt the same as a page range. I thought you meant, well...page range.

So. Where are you? Do you need help in making sections? In unlinking them? Getting a prompt? What do you need exactly? You have the method. Make distinct Sections. Put a watermark in the header of the Section you want it in.

 
I wanted the user to be able to answer the prompt "What page(s) do you want the Watermark to appear on?" with an answer similar to a printer dialog, "4-5" would be page 4 and 5 in Words page count of the document. That is why I said page range. Right now I have nothing in code. I don't understand enough about VBA in Word. I can record the basic macro but it errs on replay. I appreciate the comments but I'm giving up on this one for now as I don't have the time or inclination to delve deeper into Word, since I hardly ever use it.
Thanks,
renigar
 
Back to my first answer. Watermarks do not apply over a page range. They apply over a Section. So you need to call the action for a Section, NOT a page range.

Say your pages cover more than one Section...it won't work. Say your Section has more pages than 4-5...too bad, ALL pages in that Section will have the watermark.

So, do you want something that will make NEW sections?

 
You are correct. I think you could agree though that a section can cover a range of pages from 1 to many. I want the macro to make a new section and apply the watermark to that section. I would still like it to prompt the user for the text to use and the location of that section in the document. I would also like it to be possible to run the macro again should the user need to insert another section with a watermark somewhere else in the document.
 
I would also like it to be possible to run the macro again should the user need to insert another section with a watermark somewhere else in the document.

Easy. Run the macro again. Or, prompt the user asking if they want another Section break/watermark.

I would still like it to prompt the user for the text to use and the location of that section in the document.
And how are you dealing with "location"? By page number(s)? Pages numbers are tricky things in Word.


To do what you seem to be asking (for pages 4-5) means:

1. finding the point just BEFORE the range of the starting page (e.g. 4). this is not always easy.
2. inserting a Section break.
3. finding the point just BEFORE the range of the page AFTER the last page of the new Section (e.g. 6)
4. going into the Section AFTER the new Section and making it NOT Same as Previous.
5. going into the New Section and making it NOT Same as Previous
6. inserting the watermark.

You must do the changes to Same as Previous first...otherwise you will have a nightmare of trying to fix/adjust things afterwords.

 
> I think you could agree though that a section can cover a range of pages from 1 to many

Ot any portion thereof. A section can start anywhere on a page.

>To do what you seem to be asking

Actually the basic code for this is relatively straightforward. However, there are a number of significant repercussions to doing this, which is almost certainly why Microsoft have not implemented a simple interface to configure this themsleves; they don't want to be blamed when it blows up in your face.

Some simple examples. Assume I apply a watermark to pages 7 thru 9
1) I now add a whole extra page of text somnewhere around about page 5. Do I want the watermark to move? Or do I want it to stick with page 7?

2) I need to insert a new section on page 8 to enforce some formatting on that page that differes from the rest of the document. What happens to my watermark?
 


Enquiring minds want to know!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
It blows up in your face. At the very least it is likely the Section breaks must be adjusted.

"Actually the basic code for this is relatively straightforward. "

Maybe yes, maybe no. Finding the start of a page - or rather a single character before it - can be slippery. Especially if you do not know how to find accurate range parameters.

 
Private Sub CreatePageRangeSection(startpage As Long, stoppage As Long)
Dim rng As Word.Range

Set rng = ActiveDocument.GoTo(wdGoToPage, wdGoToAbsolute, startpage)
rng.InsertBreak Type:=wdSectionBreakNextPage
rng.Sections(1).Headers(1).LinkToPrevious = False

Set rng = rng.GoTo(wdGoToPage, wdGoToAbsolute, stoppage + 1)
rng.InsertBreak Type:=wdSectionBreakNextPage
rng.Sections(1).Headers(1).LinkToPrevious = False

Set rng = rng.GoTo(wdGoToSection, wdGoToPrevious)
rng.Sections(1).Headers(1).Range.Text = "Hello" ' demonstrate with a bit of text
End Sub
 
Thank you strongm for posting this code but I must admit that with my feeble knowledge I don't know what to do with it. Specifically what to do with a Private Sub. Maybe you could recommend a decent book that explains this in plain english. I do almost everything in Excel and have not come across a need or possess the knowledge of what a private sub could do for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top