PDA

View Full Version : Solved: Watermarks with Headers/Footers



Marcus15
07-19-2005, 07:45 AM
Hi all

I have a letter template that has a footer on the 1st page only. I then run macro which inserts the print commands in the 1st page header (see below)


ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Select
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&l1S""", PreserveFormatting:=True
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&b1M""", PreserveFormatting:=True


The problem occurs when I insert a Printed Watermark on the document and run the above commands the watermark on the 1st page disappears (subsequent pages have the watermark OK)

Is it possible to add to / alter the above code in some way so that it does not effect the watermark on any pages.

Any assistance would be gratefully appreciated.

Marcus

MOS MASTER
07-19-2005, 01:23 PM
Hi and Welcome to VBAX! :hi:

Do you have a sample document (strip private stuff) which has this behavior. I guess it's in the page setup properties but I'm not sure...would like to see it first.
HTH, :whistle:

Marcus15
07-20-2005, 12:26 AM
Thanks the reply Joost,

How does one attach / upload a file ?

Although you can replicate the behavior quite easily by setting up a document with a "Different 1st Page" setting in the Headers and Footer section within Page Setup. Make two pages and apply a standard Printed Watermark (i used ASAP).

IF you run the code in my 1st post on this document the print codes will be inserted but the watermark will disappear from the 1st page (the first page footer stays ) THe Watermark is fine on the second and subsequent pages.
Thanks


Marcus

sandam
07-20-2005, 06:16 AM
I have the same problem. I work for a law firm and to print a draft document I have to change the different first page footer property to false so that draft prints on both pages. Unfortunately I have yet to get it to do the watermark regardless :( If its not neccessary to have the footer that is what I would suggest you do. However if it is, well if anyone can find a solution it's Joost :)

And to attach you need to use the Go Advanced option on a reply.

fumei
07-20-2005, 09:50 AM
Try using a Range object, as in:
Dim oRange As Word.Range
Set oRange = _
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range

With oRange.Fields
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&l1S""", PreserveFormatting:=True
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&b1M""", PreserveFormatting:=True
End With
Set oRange = Nothing

MOS MASTER
07-20-2005, 01:09 PM
Hi Marcus, :yes

Now I know how your page setup is set I know what's happening.

Gerry of course posted excellent code which will solve your problem.
But perhaps you'd like to know the difference between Gerry's code and yours? (A part from the speed add in Gerry's code)

The first line of your code Selects the range of the firstpage header. (This means from start till end)
Your second code adds a field to the selection. Now your full range was selected and your second line is overwriting ALL that is in the firstpage Header.

So now your asking..why is my watermark gone? Well simple a Watermark is nothing more then a Shape (in your case WordArt) in your header. (So the shape was in the firstpage header range that was overwritten by your second code line)

The difference with Gerry's code is that it works directly on the range so the add method appends to the range ratter then overwriting it.

The solution was already there so I hope this clarifies it for you?

Enjoy, :whistle:

Marcus15
07-22-2005, 02:59 PM
Thanks for the code Gerry , and for explaining it Joost. I have to say i though that's what my code was doing but was not sure how to avoid it.
Currently on holiday so won't get to try the code until next wednesday (27th). But i am sure that it will work so will close the thread. Thanks for all who helped

Marcus

MOS MASTER
07-22-2005, 03:05 PM
Hi Marcus, :yes

Glad we could help you and enjoy your holidays! :whistle:

Marcus15
07-27-2005, 03:03 AM
Thanks Joost,
Am now back from holiday and have tested code
Unfortunately i 'jumped the gun' a bit in my positive view of the outcome and closed the thread prematurely. Is there a way of removing the SOLVED status of a thread ?
The problem now is :
The code places the PrintCode field text within the main body of the document rather than in the 1st page header where it needs to be, ie the printcode text needs to be literally the first thing on the page.

Marcus

fumei
07-27-2005, 06:42 AM
Are you saying the code does NOT place it in the header, that it places it in the document?

Marcus15
07-27-2005, 08:22 AM
Yes, the code does not appear in the header, but is placed within the document.

After, a little bit more playing the code. I now have the document producing the code in the header without making the watermark disappear BUT when the document prints, the watermark appear at the front on a seperate page.

The document shouold be producing a Black/White & duplex with a footer on the first page and a watermark on ALL pages.
Currently i get an initial page with a coloured watermark only, then a second and third pages which are duplexed b/w with a footer and no watermark on the front (2nd) page and on the back (3rd page) it prints correctly b/w with watermark and no footer

The code so far is


ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Select
ActiveDocument.Bookmarks("PrintCode1").Select

Dim oRange As Word.Range
Set oRange = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range

With oRange.Fields
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&l1S""", PreserveFormatting:=True
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&b1M""", PreserveFormatting:=True
End With
Set oRange = Nothing



Thanks for the assistance so far

Marcus

fumei
07-27-2005, 08:57 AM
1. I am not sure at all about the shift from colour to B/W - this seems odd.

2. why are you making a selection first? I do not understand why you are doing this.

3. Joost suggested posting up a file. Could you do that please? that way we can take a look at the real thing.

MOS MASTER
07-27-2005, 09:44 AM
Thanks Joost,
Am now back from holiday and have tested code
Unfortunately i 'jumped the gun' a bit in my positive view of the outcome and closed the thread prematurely. Is there a way of removing the SOLVED status of a thread ?
The problem now is :
The code places the PrintCode field text within the main body of the document rather than in the 1st page header where it needs to be, ie the printcode text needs to be literally the first thing on the page.

Marcus

Hai Marco, :yes

That seams strange all of a sudden something must have changed. Please post a sample of your genuine workbook (Stripped from private stuff but leave structures intact)

HTH, :whistle:

MOS MASTER
07-27-2005, 09:49 AM
Yes, the code does not appear in the header, but is placed within the document.

After, a little bit more playing the code. I now have the document producing the code in the header without making the watermark disappear BUT when the document prints, the watermark appear at the front on a seperate page.


Ok now I notice there is more posting in this thread I mist! :yes (Don't forget my previous request)

The behaviour of the first page appear at the front on a seperate page seams to indicate a wrong page setup settings somewhere in your document. (So whe have to see it)

Further more do you really need the inserted stuff to be fields? Couldn't you settle for just text inserted in the header? (In other words does that data change because you're using fields and are they deppended?)

Text would eas the code a lot.

And like Gerry said why is the code changed the way it is know? This was and could be much more efficient. (First two sentences are redundant in the code if the header is empty there's no need for a bookmark!)

HTH, :whistle:

Marcus15
07-29-2005, 12:16 AM
Find attached a document that I have made which includes the various elements which are needed and exhibits the behaviour.

The document needs to have :
First Page Footer

Watermark on all Pages

Print commands need to be removed after use as different printcodes may be issued next time the document needs to be printed



I have included the code which should produce a b/w print double sided. The code is in the only module.



This code when printed does place the code in the header but it produces a three page print



Page 1 : Simplex, with watermark in colour and nothing else just the watermark

Page 2/3 : Duplex, B/W, with watermark on back of page only (page 3) (no watermark on Page 2)



Further more do you really need the inserted stuff to be fields? Couldn't you settle for just text inserted in the header? (In other words does that data change because you're using fields and are they deppended?)

Text would eas the code a lot.

And like Gerry said why is the code changed the way it is know? This was and could be much more efficient. (First two sentences are redundant in the code if the header is empty there's no need for a bookmark!)

HTH, :whistle:

The print codes do not need to be fields as long as after printing these print codes can be removed as different print codes may used next time the document is printed.

Marcus

MOS MASTER
07-29-2005, 04:29 AM
Hi Marcus, :yes

Ok will take a look at it soon. :whistle:

MOS MASTER
07-29-2005, 02:56 PM
Hi Marcus, :yes

I'm very sorry but I'm not able to reproduce the problem on my side!

Like we suggested before I changed the code to:
Option Explicit

Sub WatermarkPrintTest()
Dim oRange As Word.Range
Set oRange = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range

With oRange.Fields
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&l1S""", PreserveFormatting:=True
.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PRINT 27""&b1M""", PreserveFormatting:=True
End With
ActiveDocument.PrintOut Background:=False, Copies:=1
Set oRange = Nothing
End Sub


This runs wel over here in Word 2002, XP and 2003...so I'm not sure on which version you are and why you have this problem on your side of the channel....

After execution the Watermark is still there....:whistle:

I'm not adding the code to your othere question cause I think we need to focus on solving this problem with the disappearing watermark first.

So what version are you on? And did you run the attachment before you posted it and the watermark disappears?

Marcus15
08-01-2005, 12:09 AM
Dear All

Eureka !!!!.

Thanks for all your assistance so far but my boss and i spent last Friday looking at this code and have come up with a solution which entails getting word VB to insert the watermark as well as the print code instead of going through the FOrmat - Background - Printed Watermark route.
The code's a bit messy and no doubt could be more efficient but it so far appears to work. I hope to post the code when i have finished tidying it up because no doubt some of you may be able to suggest ways to make it more efficient.

Thanks
Marcus

MOS MASTER
08-01-2005, 09:48 AM
Hi Marcus, :yes

Glad to hear you've found your sollution! :thumb

sandam
08-16-2005, 02:19 AM
*Performs thread necromancy - ooooh aaaaah*

Hi there Marcus. I was wondering if you could post the code that sorted the problem out for you as I have been having the same problem. You said you would and I've been waiting with baited breath ever since :). Even if its still messy ;)

MOS MASTER
08-16-2005, 10:27 AM
Indeed I'd still like to see that one too! :yes

Marcus15
08-25-2005, 01:21 AM
Hi All,
After much playing about with getting the code working as best i can for the users (secretaries!) and a few days off, i attach the code as it is. I have removed some of code which is confidential but hopefully the remainder will work w.r.t to print control and watermarks. Have included the user form which allows you to select which print command to use and whether you want to insert a watermark and which one to choose.
The watermark inserter only works if the document has one section which fortunately is ok for most of our documents.
Have fun looking at it. Unfortunately I may have to re-design it totally as a new printer has just arrived which does not support the HP driver and PCL commands i am using so i am back to square 1 !!!

regards
Marcus

MOS MASTER
08-25-2005, 02:40 PM
Hi Marcus, :yes

Thanx for sharing! :thumb

sandam
08-30-2005, 04:34 AM
indeed, thank you. I shall be perusing this today :)