Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2018, 12:33 PM
steve_lemon steve_lemon is offline Word 2016/365 Nightmare with Watermarks - Advice needed Windows 10 Word 2016/365 Nightmare with Watermarks - Advice needed Office 2016
Novice
Word 2016/365 Nightmare with Watermarks - Advice needed
 
Join Date: Mar 2018
Posts: 5
steve_lemon is on a distinguished road
Default Word 2016/365 Nightmare with Watermarks - Advice needed

I've been having a nightmare trying to apply a watermark to a word document via a VBA Macro.

It shouldn't be a difficult thing to achieve, but this has proved really challenging. To add insult to injury, this works fine if you save your Word Document/Template in compatibility mode, so it seems something has changed with the new version of Word when it comes to applying Watermarks.



I will provide the code below, but just before I will explain briefly how the document is setup, as I feel this has something to do with the problem, but like I said this works in compatibility mode, so why not for the modern format.

The document has a different first page Header, and it uses Mirror Margins. When you use the inbuilt water mark feature it only applies it to the first page. When you VBA it to ensure it applies to all pages in the document, on page 1 it is perfect. On page 2 the watermark hangs off the left-hand side of the page (can only see some of the watermark), and on the Page 3 (or odd pages) it hangs off the right-hand page. All my attempts to correct the positioning during the macro have failed.

Why is this such a nightmare and what am I doing wrong with this code?

Code:
With ActiveDocument
  'Add watermark to each header in the first section
  With .Sections.First
    i = 0
  
    For Each myHeader In .Headers
      
      'Check we have a valid header record object to avoid run-time error
      If myHeader.Exists Then
        Set myShape = myHeader.Shapes.AddTextEffect(0, "DRAFT", "Times New Roman", 144, False, False, 0, 0)
  
        With myShape
          i = i + 1
          .Name = "Draft" & CStr(i)
          .TextEffect.NormalizedHeight = False
          .Line.Visible = False
          .Fill.Visible = True
          .Fill.Solid
          .Fill.ForeColor.RGB = RGB(192, 192, 192)
          .Fill.Transparency = 0
          .Rotation = 315
          .LockAspectRatio = True
          .Height = CentimetersToPoints(5.69)
          .Width = CentimetersToPoints(16.67)
          .WrapFormat.AllowOverlap = True
          .WrapFormat.Side = wdWrapNone
          .WrapFormat.Type = 3
          .RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
          .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
          .Left = wdShapeCenter
          .Top = wdShapeCenter
        End With
  
        .Range.FormattedText.ShowAll = False
      End If
    
    Next myHeader
  End With
  
  With .ActiveWindow.View
    .ShowMarkupAreaHighlight = False
    .ShowComments = False
    .ShowRevisionsAndComments = False
  End With
  
  .FormattingShowClear = True
End With
Any advice or verification that this isn't normal and the behaviors have changed gratefully received.

Steve
Reply With Quote
  #2  
Old 03-03-2018, 09:57 PM
gmayor's Avatar
gmayor gmayor is offline Word 2016/365 Nightmare with Watermarks - Advice needed Windows 10 Word 2016/365 Nightmare with Watermarks - Advice needed Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Your code works OK here in Word 2016.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-04-2018, 04:25 AM
steve_lemon steve_lemon is offline Word 2016/365 Nightmare with Watermarks - Advice needed Windows 10 Word 2016/365 Nightmare with Watermarks - Advice needed Office 2016
Novice
Word 2016/365 Nightmare with Watermarks - Advice needed
 
Join Date: Mar 2018
Posts: 5
steve_lemon is on a distinguished road
Default

Did you have mirrored margins within your document, and a different first page header?
Reply With Quote
  #4  
Old 03-04-2018, 07:39 AM
gmayor's Avatar
gmayor gmayor is offline Word 2016/365 Nightmare with Watermarks - Advice needed Windows 10 Word 2016/365 Nightmare with Watermarks - Advice needed Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I used the document from https://www.msofficeforums.com/word-...ories-not.html with the shapes removed using the macro in that thread.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 03-04-2018, 09:19 AM
steve_lemon steve_lemon is offline Word 2016/365 Nightmare with Watermarks - Advice needed Windows 10 Word 2016/365 Nightmare with Watermarks - Advice needed Office 2016
Novice
Word 2016/365 Nightmare with Watermarks - Advice needed
 
Join Date: Mar 2018
Posts: 5
steve_lemon is on a distinguished road
Default

Many thanks for your time, after your success I went back and tried the macro on a brand new document and it worked for me too.

I then went back to the original template and still had the same problems! There must be something in the headers or margins that is affecting the placement of the Draft watermark. There is too much time invested in my template to start again, so I started looking for other ways around the problem.

The header in the document are already being used to store page numbers in frames, with mirror placements on add and even pages and bookmarks etc. However, when I checked the template I noticed the footers were not being used.

I changed the macro to use the footers instead, and hey-presto it's working. Can't explain why, grateful I have a solution, and a tip for other keep at it and think outside the box.

Many thanks for you time and giving me the emphasis to check again.
Cheers

Steve
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Surface 4 Pro Clipping Advice Needed RicKaysen OneNote 0 11-02-2015 04:26 PM
Word 2016/365 Nightmare with Watermarks - Advice needed HELP/ADVICE NEEDED. Testing Excel Accessibility guidelines cmc89 Excel 1 03-29-2012 03:41 PM
Advice Needed on Possible VBA usage HorizonSC Excel Programming 2 09-21-2011 02:47 AM
Word 2016/365 Nightmare with Watermarks - Advice needed For techies - forensic detection advice needed please Donald Word 1 04-14-2011 04:22 PM
Box or border help advice needed ipbr21054 Drawing and Graphics 0 07-18-2010 10:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft