Word 2007 working with watermarks, & objects

diana
3StarLounger
Posts: 279
Joined: 01 Jun 2010, 00:27

Word 2007 working with watermarks, & objects

Post by diana »

Word 2007 working with watermarks, working with Objects.

environment:
Company has Office 2007 SP2, in compatiablilty mode ie office files are saved with the '.doc' extensions. not full office 2007 full mode with file extensions '.docx'

I've been working with watermarks.

Working with Microsoft out of the box watermarks.
goto ribbon Page Layout, click Watermark, Custom Watermark

Note: I did notice Microsoft default watermarks are inserted as WordArt

Advantages:
- allows you to easily add, remove watermarks in the entire document
- standard watermarks can be used eg Copy, Draft, Confidential

disadvantages:
Text - forced to use default microsoft watermark templates
Picture watermark - setup and deploy to client pcs. deployment and training involved.

Our company letterhead if you like has 2 'watermarks' - Main 'watermark' on the first page, follower 'watermark' for all other pages
- unable to create and insert dual watermarks into the one document (well you can, its just more clicking, interaction and formatting eg for each section header "Unlink to Previous section) etc


Therefore company watermarks were created as WordArt objects. This allows for company fonts, styles and formatting.
Custom code was written to insert watermarks correctly into the entire document regardless of document page setup eg First Page header, Primary header, Odd/Even headers, orientation = either Portrait or Landscape etc


My goal is to write custom code to remove only the company watermarks.

The reason why I would like to identify, select and delete ONLY the company watermarks, is in the word documents there are other objects, eg client logos, page numbers inserted as floating 'objects', other watermarks and images etc. I dont want to touch (accidentally delete) these items, only the company watermarks.


so far Ive researched and discovered the following:
in word 2007- and previous versions of Word you cant seem to identify or flag the watermark/object inserted.

for example I attempted to bookmark the "object", however it appears you cant bookmark an object.

I noticed using code automation if an object is inserted, Word has an internal reference number eg 'object21', next object inserted is'object22' etc

If I create a watermark image file stored on the local pc directory. In the document create a fieldcode reference link to this image.
Result: the watermark image displays in the docuemnt.
Other considerations:
The document is used for both internal and external use, which means this will work only for internal documents. If the documents are emailed outside to clients watermarks are still required to display, this method wont display the watermarks. as this is setup only within our environment.


The company is currently on Office 2007.

Ive installed Office 2010. and taken a look at Word 2010 watermarks, It appears the functionality to use and work with watermarks has improved.
Word 2010 does allow you to bookmark objects. if the bookmarks are in the documents header, you can easily GoTo the bookmark in teh header = easy to work with. Previous version of Word, you had to have the header open before the GoTo bookmark was enabled.
If I create bookmarked watermarks in an office 2010 document saved as .docx. Open the document in Word 2007, the result is; the bookmarked watermarks are not backwards compatiable and I cant use or select the bookmark.


I can redesign the company watermarks if need be.

My questions are:
- how can i easily setup watermarks with a marker or identifier so i can easily insert and remove specific watermarks using code?
- should I use objects?
- or a different method?
- can i create a heading style? for the watermark
- other method to identify?
- how have others done this successfully

see screen captures.

many thanks

diana
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78565
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2007 working with watermarks, & objects

Post by HansV »

When you create a shape (such as a WordArt object), you can assign it a name. Here is an example:

Code: Select all

Dim shp As Shape
Set shp = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
  .Shapes.AddTextEffect(PresetTextEffect:=msoTextEffect12, Text:="Diana", _
  FontName:="Calibri", FontSize:=18, FontBold:=False, FontItalic:=False, _
  Top:=100, Left:=100)
shp.Name = "Watermark1"
Later on, you can refer to the shape by name, e.g.

Code: Select all

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes("Watermark1").Delete
Best wishes,
Hans

diana
3StarLounger
Posts: 279
Joined: 01 Jun 2010, 00:27

Re: Word 2007 working with watermarks, & objects

Post by diana »

thanks Hans.

If I have the shape created as a quick part and insert
on inserting the watermark, can I assign a name?
or is it only on manually creating a shape?

dd

User avatar
HansV
Administrator
Posts: 78565
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2007 working with watermarks, & objects

Post by HansV »

If you have already created a shape, you can assign it a name as follows:
- Select the shape.
- Activate the Visual Basic Editor.
- Activate the Immediate window (Ctrl+G).
- Type the following, then press Enter:

Selection.ShapeRange(1).Name = "MyName"
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word 2007 working with watermarks, & objects

Post by ChrisGreaves »

diana wrote:Word 2007 working with watermarks, working with Objects.
Wiorking with objects it's not, but I spent the earlier part of this week playing around with PostScript.

Code: Select all

Sub InsertWaterMark()
    Dim strText As String
    strText = InputBox("Enter your watermark text", "InsertWaterMark", "DRAFT " & Application.UserName)
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False
    Selection.TypeText Text:="Print \p page "" /Wmark (DRAFT) def /WSize 100 def /Wrot 45 def wp$x wp$right sub wp$left add 2 div wp$y wp$top sub wp$bottom add 2 div translate Wrot rotate /Helvetica-BoldOblique findfont WSize scalefont setfont .7 setgray 3 setlinewidth Wmark stringwidth pop 2 div neg WSize .4 mul neg moveto Wmark true charpath stroke "" "
End Sub
This code inserts a {fieldcode} in Word2003; the watermark isn't visible until I print (to PDF, printer etc.), but if you are having problems with objects, perhaps playing with fieldcodes might be easier?
(Difficult to read inline, so also attached as a TXT file)
http://word.tips.net/T000461_Adding_a_Diagonal_Watermark_with_a_PostScript_Printer.html
You do not have the required permissions to view the files attached to this post.
Last edited by ChrisGreaves on 02 Jun 2011, 12:43, edited 1 time in total.
He who plants a seed, plants life.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Word 2007 working with watermarks, & objects

Post by macropod »

Coincidentally, I've just been working on a similar issue in another forum. Here's some code for both inserting & deleting custom watermarks. Simply change the watermark's path & name, and any other relevant parameters, to suit your setup.

Code: Select all

Sub Insert_Watermarks() 
  Application.ScreenUpdating = False 
  Dim i As Long, j As Long, HdFt As HeaderFooter, Shp As Shape 
  With ActiveDocument 
    For i = 1 To .Sections.Count 
      For Each HdFt In .Sections(i).Headers 
        j = j + 1 
        With HdFt 
          If .LinkToPrevious = False Then 
            Set Shp = HdFt.Shapes.AddPicture(FileName:= _ 
            strUser & "\Application Data\Microsoft\Templates - Workgroup\DRAFT.gif", _ 
            LinkToFile:=False, SaveWithDocument:=True) 
            With Shp 
              .Name = "WaterMark" & Format(j, "0000") 
              .PictureFormat.Brightness = 0.5 
              .PictureFormat.Contrast = 0.5 
              .LockAspectRatio = True 
              .Width = CentimetersToPoints(16.5) 
              .WrapFormat.AllowOverlap = True 
              .WrapFormat.Side = wdWrapNone 
              .WrapFormat.Type = 3 
              .RelativeHorizontalPosition = wdRelativeVerticalPositionMargin 
              .RelativeVerticalPosition = wdRelativeVerticalPositionMargin 
              .Left = wdShapeCenter 
              .Top = wdShapeCenter 
            End With 
          End If 
        End With 
      Next 
    Next 
  End With 
End Sub 

Sub Delete_Watermarks() 
  Application.ScreenUpdating = False 
  Dim i As Long, HdFt As HeaderFooter, Shp As Shape 
  With ActiveDocument 
    For i = 1 To .Sections.Count 
      For Each HdFt In .Sections(i).Headers 
        With HdFt 
          If .LinkToPrevious = False Then 
            For Each Shp In .Range.ShapeRange 
              If InStr(Shp.Name, "WaterMark") > 0 Then Shp.Delete 
            Next 
          End If 
        End With 
      Next 
    Next 
  End With 
End Sub
Paul Edstein
[Fmr MS MVP - Word]

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word 2007 working with watermarks, & objects

Post by ChrisGreaves »

macropod wrote:Coincidentally, I've just been working on a similar issue ...
Better than mine.
Your's, being a SHP shows up in the Word document; mine waits until the doc is printed (sniff!)
He who plants a seed, plants life.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Word 2007 working with watermarks, & objects

Post by macropod »

ChrisGreaves wrote:
macropod wrote:Coincidentally, I've just been working on a similar issue ...
Better than mine.
Your's, being a SHP shows up in the Word document; mine waits until the doc is printed (sniff!)
Yes, my world famous :fanfare: Microsoft Word Date Calculation Tutorial :fanfare: , at http://lounge.windowssecrets.com/index. ... pic=249902" onclick="window.open(this.href);return false; has field coding for doing similar things. Your use of the PRINT field is a nice touch, though it does mean the watermark can't be displayed on screen and, from what I can see, is limited to use with postscript printers.
Paul Edstein
[Fmr MS MVP - Word]

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Word 2007 working with watermarks, & objects

Post by ChrisGreaves »

macropod wrote: Your use of the PRINT field is a nice touch, though it does mean the watermark can't be displayed on screen and, from what I can see, is limited to use with postscript printers.
Not my design (a more primitive version is available in Word Hacks from O'Reilly) and yes, it has limitations.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78565
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Word 2007 working with watermarks, & objects

Post by HansV »

Unfortunately, attachments in the Windows Secrets Lounge are only available to logged in members. Macropod's justly famous Date Calculation Tutorial, as well as a couple of others, are freely downloadable from Graham Mayor's download page - go to http://www.gmayor.com/downloads.htm" onclick="window.open(this.href);return false; and scroll down to Third party downloads.
Best wishes,
Hans

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Word 2007 working with watermarks, & objects

Post by macropod »

ChrisGreaves wrote:Not my design (a more primitive version is available in Word Hacks from O'Reilly) and yes, it has limitations.
And guess where the O'Reilly's field code came from (esp Chapter 8) ...
Paul Edstein
[Fmr MS MVP - Word]

diana
3StarLounger
Posts: 279
Joined: 01 Jun 2010, 00:27

Re: Word 2007 working with watermarks, & objects

Post by diana »

thank you

macropod is it reallly a coincident? ah! the big questions in life...