Solved

Create macro in word 2003 to insert watermark on pages designated as letterhead

Posted on 2008-06-24
2
892 Views
Last Modified: 2012-05-05
I need to create a macro in word 2003 that will insert a background preferably onto all letter headed defined paper. The image when inserted should be positioned behind the text and will cover the entire page like a watermark scaled at 100%: -

Sub MBSBACKGROUND()
'
' MBSlhead Macro
' Insert MBS letter head - Macro recorded 28/01/2008 by luke.griffiths
'
    ActiveDocument.Sections(1).Range.Select
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
        "\\*****\MBSLhead.jpg", LinkToFile:=False, _
        SaveWithDocument:=True).Select
    Selection.ShapeRange.Name = "WordPictureWatermark1"
    Selection.ShapeRange.PictureFormat.Brightness = 0.5
    Selection.ShapeRange.PictureFormat.Contrast = 0.5
    Selection.ShapeRange.LockAspectRatio = True
    Selection.ShapeRange.Height = CentimetersToPoints(29.7)
    Selection.ShapeRange.Width = CentimetersToPoints(21)
    Selection.ShapeRange.WrapFormat.AllowOverlap = True
    Selection.ShapeRange.WrapFormat.Side = wdWrapNone
    Selection.ShapeRange.WrapFormat.Type = 3
    Selection.ShapeRange.RelativeHorizontalPosition = _
        wdRelativeVerticalPositionMargin
    Selection.ShapeRange.RelativeVerticalPosition = _
        wdRelativeVerticalPositionMargin
    Selection.ShapeRange.Left = wdShapeCenter
    Selection.ShapeRange.Top = wdShapeCenter
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

It would be perfect if the above could be modified, so instead of appearing on every page of the letter, the watermark would only appears on pages that have been designated letterhead in File/Page Setup/Paper/Paper Source.

Any help would be much appreciated.
0
Comment
Question by:llantwit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
wobbled earned 500 total points
ID: 21855578
Here you go. - I've slightly modified your code so that it checks each section etc

Sub MBSBACKGROUND()

Dim x As Integer, n As Integer
   
    x = 1
   
    Do While x <= Selection.Information(wdNumberOfPagesInDocument)
       
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=x
       
        n = Selection.Information(wdActiveEndSectionNumber)
       
        If Selection.PageSetup.PaperSize = wdPaperLetter Then
            With Selection.ShapeRange
                ActiveDocument.Sections(n).Range.Select
                ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
                Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
                    "\\*****\MBSLhead.jpg", LinkToFile:=False, _
                    SaveWithDocument:=True).Select
                .Name = "WordPictureWatermark1"
                .PictureFormat.Brightness = 0.5
                .PictureFormat.Contrast = 0.5
                .LockAspectRatio = True
                .Height = CentimetersToPoints(29.7)
                .Width = CentimetersToPoints(21)
                .WrapFormat.AllowOverlap = True
                .WrapFormat.Side = wdWrapNone
                .WrapFormat.Type = 3
                .RelativeHorizontalPosition = _
                    wdRelativeVerticalPositionMargin
                .RelativeVerticalPosition = _
                    wdRelativeVerticalPositionMargin
                .Left = wdShapeCenter
                .Top = wdShapeCenter
                ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
            End With

        End If

        x = x + 1

    Loop
 
end sub
0
 

Author Comment

by:llantwit
ID: 21856471
Could the macro be changed so that instead of selecting (wdPaperLetter): -

If Selection.PageSetup.PaperSize = wdPaperLetter Then

It will select the pages that are printing from tray 3, which contains the headed paper.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question