Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jan 2004
    Thanked 0 Times in 0 Posts

    Using watermark dialog with VBA (Word 2002)

    I raised this problem in a Microsoft newsgroup some months ago but maybe loungers will be able to do better for me!
    I am trying to create a macro to insert a "DRAFT" watermark. I want it to work on multi-section documents with headers of later sections not linked to the previous header. Experimenting with the Format/Background/Printed Watermark dialog and the macro recorder shows that extra code is generated if there is an unlinked later section. So the best way to keep the macro general seems to be to execute the dialog using VBA. But I cannot find it in the list of "wddialog" names. Can anyone kindly suggest how I can get at the dialog using VBA?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Using watermark dialog with VBA (Word 2002)

    <P ID="edit" class=small>(Edited by jscher2000 on 12-Jun-04 16:19. I forgot the attachment...)</P>In looking at the various dialogs in the Dialogs collection, none pops out at me as matching the Printed Watermark dialog. (List attached by number.)

    Since you know what the recorded code looks like, why not just work with that? You could scan through the sections, checking each header for "link to previous" and add the Shape as needed. No?
    Attached Files Attached Files

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Using watermark dialog with VBA (Word 2002)

    There is something strange with the macro as recorded by Word: it uses an invalid value for PresetTextEffect in the AddTextEffect instruction, so the macro can't be run. Also, the code will not let me assign a name as in the recorded macro. If I correct this, the macro works, sort of, but the Format | Background | Printed Watermark dialog reports "No watermark". <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

    Here is my macro:

    <code>Sub CreatePseudoWaterMark()</code>
    <code> Dim hdr As HeaderFooter</code>
    <code> Dim intSec As Integer</code>
    <code> Dim i As Integer</code>
    <code> For intSec = 1 To ActiveDocument.Sections.Count</code>
    <code> For Each hdr In ActiveDocument.Sections(intSec).Headers</code>
    <code> If hdr.Exists Then</code>
    <code> If intSec = 1 Or hdr.LinkToPrevious = False Then</code>
    <code> i = 1 + 1</code>
    <code> hdr.Range.Select</code>
    <code> With hdr.Shapes.AddTextEffect(msoTextEffect1, _</code>
    <code> "CONCEPT", "Times New Roman", 1, False, False, 0, 0)</code>
    <code> If i = 1 Then</code>
    <code> .Name = "PowerPlusWaterMarkObject" & i</code>
    <code> End If</code>
    <code> .TextEffect.NormalizedHeight = False</code>
    <code> .Line.Visible = False</code>
    <code> .Fill.Visible = True</code>
    <code> .Fill.Solid</code>
    <code> .Fill.ForeColor.RGB = RGB(192, 192, 192)</code>
    <code> .Fill.Transparency = 0.5</code>
    <code> .Rotation = 315</code>
    <code> .LockAspectRatio = True</code>
    <code> .Height = InchesToPoints(2)</code>
    <code> .Width = InchesToPoints(7)</code>
    <code> .WrapFormat.AllowOverlap = True</code>
    <code> .WrapFormat.Side = wdWrapNone</code>
    <code> .WrapFormat.Type = 3</code>
    <code> .RelativeHorizontalPosition = _</code>
    <code> wdRelativeVerticalPositionMargin</code>
    <code> .RelativeVerticalPosition = _</code>
    <code> wdRelativeVerticalPositionMargin</code>
    <code> .Left = wdShapeCenter</code>
    <code> .Top = wdShapeCenter</code>
    <code> End With</code>
    <code> End If</code>
    <code> End If</code>
    <code> Next hdr</code>
    <code> Next intSec</code>
    <code> ActiveWindow.View.SeekView = wdSeekMainDocument</code>
    <code> ActiveWindow.View = wdPrintView</code>
    <code> Set hdr = Nothing</code>
    <code>End Sub</code>

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Using watermark dialog with VBA (Word 2002)

    You caught me not testing my code. <img src=/S/blush.gif border=0 alt=blush width=15 height=15> I got slightly better results by creating an intermediate object, but the interoperability with the dialog suffered (it seems to see only the first watermark).

    Sub CreatePseudoWaterMark()
    Dim hdr As HeaderFooter, wmark As Shape
    Dim intSec As Integer
    Dim i As Integer
    For intSec = 1 To ActiveDocument.Sections.Count
    For Each hdr In ActiveDocument.Sections(intSec).Headers
    If hdr.Exists Then
    If intSec = 1 Or hdr.LinkToPrevious = False Then
    i = i + 1
    Set wmark = hdr.Shapes.AddTextEffect(msoTextEffect1, _
    "SECTION " & CStr(intSec), "Times New Roman", 1, False, False, 0, 0)
    With wmark
    .Name = "PowerPlusWaterMarkObject" & CStr(i)
    .TextEffect.NormalizedHeight = False
    .Line.Visible = False
    .Fill.Visible = True
    .Fill.ForeColor.RGB = RGB(192, 192, 192)
    .Fill.Transparency = 0.5
    .Rotation = 315
    .LockAspectRatio = True
    .Height = InchesToPoints(2)
    .Width = InchesToPoints(7)
    .WrapFormat.AllowOverlap = True
    .WrapFormat.Side = wdWrapNone
    .WrapFormat.Type = 3
    .RelativeHorizontalPosition = _
    .RelativeVerticalPosition = _
    .Left = wdShapeCenter
    .Top = wdShapeCenter
    End With
    End If
    End If
    Next hdr
    Next intSec
    ActiveWindow.View.SeekView = wdSeekMainDocument
    ActiveWindow.View = wdPrintView
    Set wmark = Nothing
    Set hdr = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts