Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 10-06-2018, 05:15 PM
gmaxey gmaxey is offline Highlighting applied to range ending in a paragraph continues to apply to text added after Windows 7 32bit Highlighting applied to range ending in a paragraph continues to apply to text added after Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub CodeSnippet_ConstrainHighlighting() ' 10/06, 1018
    Dim i As Long
    Dim MyRange As Range ' A range for the body of the doc
    ' Create a new document
    'Documents.Add DocumentType:=wdNewBlankDocument
    ' Show field codes
    ActiveWindow.View.ShowFieldCodes = True
    'Add text to the doc, format it, add field, and loop
    For i = 1 To 2
        With ActiveDocument
            ' Set the range as the very end of the document
            Set MyRange = .Range(.Content.End - 1, .Content.End - 1)
        End With
            
        ' Add text and format apply
        With MyRange
            ' Insert the file name into the document
            .Text = "Test Heading Text Here"
            ' Apply H1 style
            .Style = ActiveDocument.Styles("Heading 1")
            ' Remove numbering
            .ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
            
            '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
            ' Add highlight
            
           
            
            .HighlightColorIndex = wdYellow
            
            '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            .Collapse 0
            .HighlightColorIndex = wdAuto
            '.End = ActiveDocument.Range.End
    
            ' Add two lines
            .InsertParagraphAfter
            .InsertParagraphAfter
    
            ' Set range to end of doc
            With ActiveDocument
                Set MyRange = .Range(.Content.End - 1, .Content.End - 1)
            End With
            
            ' Insert the IncludeText field and file path
            .Fields.Add Range:=MyRange, Type:=wdFieldIncludeText, Text:="""C:\\testdoc.docx"""
    
            ' Collapse the range to the end of the document
            .End = ActiveDocument.Range.End
            .Collapse wdCollapseEnd
            ' Insert a line and a page break, but not if it's the last item in the doc
            If i < 2 Then
                .InsertParagraphAfter
                .InsertBreak Type:=wdPageBreak
            End If
        End With
    Next i
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Paragraph mark added on the top of every second page aptbs00 Word 6 09-14-2018 03:53 PM
Highlighting applied to range ending in a paragraph continues to apply to text added after Conditional Formatting - Duplicates - Apply to specified range music_al Excel Programming 1 01-25-2017 05:34 AM
Highlighting applied to range ending in a paragraph continues to apply to text added after Word changing my body text to heading text when I apply paragraph numbering ddiemetric Word 1 01-17-2017 01:10 PM
Paragraph space before - can styles apply it intelligently? timpani Word 7 10-23-2012 04:08 PM
Paragraph ending in following page tadlomc Word 1 01-18-2012 05:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:04 PM.


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