Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi there,

    We have recently redesigned our letter templates (with some great help from yourselves!), copy attached.

    We also have a macro that our users can call that inserts a watermark into every page of a document regardless of any section breaks etc. The code for that macro is:

    [codebox]Sub AddWatermark()

    'running this macro will enable a user to insert a watermark into their document
    '(where they can choose their own wording)

    Dim sect As Section
    Dim oShape As Shape
    Dim stext As String
    Dim hf As HeaderFooter

    'lets the user create a watermark through an entire document, all sections
    With ActiveDocument.Sections(1).Headers(wdHeaderFooterP rimary)
    If .Shapes.Count > 0 Then
    For Each oShape In .Shapes
    If Left(oShape.Name, 9) = "Watermark" Then oShape.Delete
    Next oShape
    End If
    End With
    'get the watermark string
    stext = InputBox( _
    Prompt:="Enter your text for your watermark. " & _
    "If your text is longer than 8 characters, enter a pipe (shift + \ key). " & _
    "For example PRIVATE | & CONFIDENTIAL", _
    Title:="Insert a watermark", _
    Default:="COPY")
    If stext = "" Then Exit Sub
    stext = Replace(stext, "|", vbCr)
    'turn off screen updates and set the view to see the headers/footers
    Application.ScreenUpdating = False
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then ActiveWindow.Panes(2).Close
    ActiveWindow.ActivePane.View.Type = wdPageView
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    'loop thru the headers in each section
    For Each sect In ActiveDocument.Sections
    For Each hf In sect.Headers
    hf.Range.Select
    If Not hf.LinkToPrevious And hf.Exists Then
    Set oShape = hf.Shapes.AddTextEffect( _
    PresetTextEffect:=msoTextEffect2, _
    Text:=stext, _
    FontName:="Arial", _
    FontSize:=66, _
    FontBold:=msoTrue, _
    FontItalic:=msoTrue, _
    Left:=0, _
    Top:=0)
    oShape.Name = "Watermark" & sect.Index & hf.Index
    oShape.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    oShape.RelativeVerticalPosition = wdRelativeVerticalPositionPage
    oShape.Left = (sect.PageSetup.PageWidth - oShape.Width) \ 4
    oShape.Top = (sect.PageSetup.PageHeight - oShape.Height) \ 6
    oShape.Fill.ForeColor.RGB = RGB(146, 146, 146)
    oShape.Line.Visible = msoFalse
    End If
    Next hf
    Next sect
    ' Back to main doc and show results
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Application.ScreenUpdating = True

    End Sub
    [/codebox]

    The macro seems to set the active document to normal view and the conflict is that a debug error appears when it comes to closing the header and footer via the code in the template in that it can't close the h/f unless print layout view is active. I thought it would be a case of simply changing to print layout view at some point, however, when stepping through the code for both the macro letter, for every F8 when I switch to Word, I only actually see print layout view where I expect to see normal view.

    Can anyone enlighten me please?

    Thanks,

    Violet

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Your code runs correctly for me in Word 2003 SP3. Whichever view the document is in before running the macro, it is in Print Layout view afterwards.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Hans,

    The macro runs fine with documents, but not when the activedocument has been created from our letter template. Now that I'm looking at my original post I don't see the attachment icon although I did upload a template - here it is again anyway just in case it wasn't there.

    Thanks,

    Violet
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Which version of Word are you using? I tried the macro in a document based on your template, this time in Word 2002 SP3, and again the macro ran correctly, without an error message.

    But the OK button on your userform did *not* work as intended - the code looks for bookmarks add1, add2 etc. but they don't exist in the document / template.

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry, that's what I get for taking shortcuts and not creating new files for posting.

    Try the new attachment. We are using Word 2003, the users all have SP2, however, I have to confess my machine is not up to date and appears to have no service packs. The issue was brought to my attention, however, by users so is affecting us all regardless of service pack.

    Thanks again,

    Violet
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Yes, now I see the behavior that you described. The problem is caused by the wdApp_WindowSelectionChange event procedure in the ThisDocument module. This event procedure disables access to the header and footer. If you remove or disable this procedure, the code will run OK.

  7. #7
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Good morning Hans,

    I thought it might mean having to sacrifice that and unfortunately, that's not an option because the bosses don't want people to be able to tamper with the disclaimer that appears in the footer area of our letter templates. I'll have to see what the people in charge want to do then.

    Thanks for your time, have a great day!

    Violet

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Does the attached version work better? It uses a boolean variable to exit the event handler if you run the AddWatermark macro.
    Attached Files Attached Files

  9. #9
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That works a treat! On the downside, we are now experiencing a conflict when using spellchecker because of the header/footer protection also. Given that, and the fact that we can't legislate for any other problems that might arise, I think they might be willing to forego the protection!

    Thanks again for all your help,

    Violet

Posting Permissions

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