Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2020, 09:22 AM
Nippy Nippy is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2016
Novice
Word Macro - Rotation Issue with Textbox
 
Join Date: Jul 2020
Posts: 3
Nippy is on a distinguished road
Default Word Macro - Rotation Issue with Textbox

[I am trying to write a macro to insert a custom watermark in my Word document.



The code works perfectly for the first two pages of the document but thereafter the the Textbox does not rotate to -45 as mentioned in the code

What am I doing wrong?

Code:
Sub CustomWatermark()

    Dim activeDoc As Document
    Dim rngDoc As Range
    Dim shpTextBox As Shape
    Dim lngPages As Long
    Dim i As Long
    Dim strWatermark As String
    
    
    Set activeDoc = ActiveDocument
    
    lngPages = activeDoc.Range.Information(wdNumberOfPagesInDocument)
    
    strWatermark = InputBox("Enter Watermark")
    
    With activeDoc
    
        For i = 1 To lngPages

            Set rngDoc = .GoTo(What:=wdGoToPage, Name:=i)
            rngDoc.Collapse wdCollapseStart
        
            Set shpTextBox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                            Left:=InchesToPoints(1), _
                                            Top:=InchesToPoints(4), _
                                            Width:=InchesToPoints(6), _
                                            Height:=InchesToPoints(2), _
                                            Anchor:=rngDoc)
            With shpTextBox
                .Line.Visible = msoFalse
                .Rotation = -45
                .WrapFormat.Type = wdWrapBehind
                .TextFrame.HorizontalAnchor = msoAnchorCenter
                .TextFrame.VerticalAnchor = msoAnchorMiddle
                                                
                With .TextFrame.TextRange
                    .Font.AllCaps = True
                    .Font.Size = "60"
                    .Font.ColorIndex = wdGray25
                    .ParagraphFormat.Alignment = wdAlignParagraphCenter
                    .Text = strWatermark
                    
                End With
            End With
        Next
    End With
    

End Sub
Reply With Quote
  #2  
Old 07-18-2020, 10:06 AM
gmaxey gmaxey is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,081
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

I don't see anything wrong. When I tested with three pages, it worked fine. However, with five pages, sometimes first two pages were rotated and sometimes only pages after the first two were rotated.



Why don't you put the watermarks in the header:

Code:
Sub CustomWatermark()
Dim oDoc As Document
Dim oRng As Range
Dim oShp As Shape
Dim i As Long
Dim strWatermark As String

    Set oDoc = ActiveDocument
    strWatermark = InputBox("Enter Watermark")
    For i = 1 To 3
      Set oRng = oDoct.Sections(1).Headers(i).Range
      oRng.Collapse wdCollapseStart
      Set oShp = oDoc.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                            Left:=InchesToPoints(1), _
                                            Top:=InchesToPoints(4), _
                                            Width:=InchesToPoints(6), _
                                            Height:=InchesToPoints(2), _
                                            Anchor:=oRng)
      With oShp
        .Line.Visible = msoFalse
        .Rotation = -45
        .WrapFormat.Type = wdWrapBehind
        .TextFrame.HorizontalAnchor = msoAnchorCenter
        .TextFrame.VerticalAnchor = msoAnchorMiddle
        With .TextFrame.TextRange
          .Font.AllCaps = True
          .Font.Size = "60"
          .Font.ColorIndex = wdGray25
          .ParagraphFormat.Alignment = wdAlignParagraphCenter
          .Text = strWatermark
        End With
     End With
   Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-18-2020, 10:20 AM
Nippy Nippy is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2016
Novice
Word Macro - Rotation Issue with Textbox
 
Join Date: Jul 2020
Posts: 3
Nippy is on a distinguished road
Default Thank you

This works perfectly and thank you

However, not clear why the .rotation = -45 does not work for two pages onwards in my code.
Reply With Quote
  #4  
Old 07-18-2020, 10:23 AM
gmaxey gmaxey is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,081
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

You and me both. Like I said, using your code it did work with three pages but when I tested with five, sometimes pages 1 and 2 ended up straight while 3-5 were rotated and sometimes pages 1 and 2 were rotated and 3-5 were straight. An oddity with Word I guess.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-18-2020, 10:29 AM
Nippy Nippy is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2016
Novice
Word Macro - Rotation Issue with Textbox
 
Join Date: Jul 2020
Posts: 3
Nippy is on a distinguished road
Default Thank you again

Thanx Greg ... I shall be using your code for my macro.
Reply With Quote
  #6  
Old 07-18-2020, 12:40 PM
eduzs eduzs is offline Word Macro - Rotation Issue with Textbox Windows 10 Word Macro - Rotation Issue with Textbox Office 2019
Competent Performer
 
Join Date: May 2017
Posts: 208
eduzs is on a distinguished road
Default

(sorry, this reply does not apply to the topic)
__________________
Backup your original file before doing any modification.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Template/Macro/QAT toolbar issue ! monkeybradders Word 1 09-13-2019 01:29 PM
Word Macro - Rotation Issue with Textbox issue with highlight macro word 2010 jamesnavoy Word VBA 2 01-29-2017 08:32 AM
Macro/VBA code to select ALL text in a textbox in microsoft excel and add a new row jyfuller Excel Programming 11 06-01-2015 08:49 PM
Word Macro - Rotation Issue with Textbox Macro to change the layout/positioning of a textbox Catty Word VBA 1 09-11-2014 04:07 PM
textbox color issue Dave Duncan Word 0 08-07-2011 10:38 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:00 PM.


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