Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
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…

738 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