Solved

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

Posted on 2008-06-24
2
872 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now