Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

920 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

13 Experts available now in Live!

Get 1:1 Help Now