• Removing watermarks

    Author
    Topic
    #498393

    Some years ago, when using Office 2003, I developed a report template that included a logo and a “Draft” watermark in the header. The report was printed onto preprinted “bond” stationery (very expensive). To remove the logo and “Draft” watermark I, in conjunction with help from the forum, developed a macro to remove both the logo and the watermark (see attached). This has continued to work fine up until now. However, the macro has decided that it no longer wishes to be useful and has stopped removing the logo and watermark.

    Can anyone help?

    Viewing 3 reply threads
    Author
    Replies
    • #1486903

      Phil

      The docx file format can’t contain macros. We need to see the code if we are to suggest fixes

      • #1486994

        Andrew
        The document is a hard copy of the code which is stored in a global template but used on the attached typical report

    • #1487061

      Interesting code. You permanently delete any floating shapes in the body of the document (thus potentially removing required content) but only toggle the visibility of the watermark. In the sample document you posted, the code appears to do what you wanted except if you run it a second time.

      However it is not particularly hard to imagine a scenario where the watermark is hidden and then another one is added over the top. Your code would then show one and hide the other so it appears nothing changed. Is there code in your template that adds a watermark (not just unhides it) which could be causing the issue you see.

      • #1487065

        Andrew hi
        As I stated in the original post the report was designed to be printed o expensive bond paper when finalised. It contained a logo on the front page, hence the remove the logo “shape”, and “DRAFT” watermarks. The intention of the code was to remove the logo and watermarks.
        Ideally we would like to remove the watermarks, which are only imbeded shapes

    • #1487127

      Phil

      Your code also turns off screen updates and doesn’t turn it on again – this might be the problem too.

      Did the document you posted show the problem with the watermark remaining? The macro worked for me to hide the watermark but it did reveal it again when I ran the macro a second time. This is a rewrite which checks each of the headers for floating shapes. I guess it is possible that the watermark might have slipped into a footer so perhaps you also need a loop for that case too. I have changed to using ranges so screen updates should no longer be an issue.

      Code:
      Sub Final_Report()
        Dim Shp As Shape, aHF As HeaderFooter, bFinal As Boolean, iResponse As Integer
        
        'On Error Resume Next
        iResponse = MsgBox("Are you sure this is to be the final report?", _
                vbYesNo + vbCritical + vbDefaultButton2, "Final Report")
        bFinal = iResponse = vbYes
        
        If bFinal Then
          While ActiveDocument.Shapes.Count > 0
            ActiveDocument.Shapes(1).Delete
          Wend
          ActiveDocument.Bookmarks("bmkReportDate").Range.Text = Format(Date, "d MMMM yyyy")
        End If
        
        For Each aHF In ActiveDocument.Sections(1).Headers
          For Each Shp In aHF.Shapes
            If Shp.Type = msoTextEffect Then
              Shp.Visible = Not bFinal
            End If
          Next Shp
        Next aHF
      End Sub
    • #1487540

      Andrew thanks again
      Works a treat.
      Thought about the problem and seem to remember there was a reason for “hiding” the watermark but can’t remember.

    Viewing 3 reply threads
    Reply To: Removing watermarks

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: