View Single Post
 
Old 07-20-2021, 10:26 PM
Peterson Peterson is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 143
Peterson is on a distinguished road
Default

I'm not exactly sure what you're trying to accomplish (it looks like you're trying to add a count to a string??), but if you have a combined document with redlines in which you need to locate all insertions in all of what in Word are referred to as "stories," e.g., main body, headers, footers, text boxes, etc., then the following code should do that:
Code:
Sub Revisions_FindAllInAllStories()
' Find insertions in all stories

' Code to loop all stories by Macropod:
' http://www.vbaexpress.com/forum/archive/index.php/t-27391.html

    Dim pRange As Range
    
    Dim dsRevision As Revision
    Dim oResDoc As Document
    Dim sngCharacters As Long

    Set oResDoc = ActiveDocument
    
    For Each pRange In ActiveDocument.StoryRanges
        Do
            For Each dsRevision In pRange.Revisions

                ' I'm just guessing what you're trying to do here.
                ' Replace this If/Then with your code:
                If dsRevision.Type = wdRevisionInsert Then
                    sngCharacters = sngCharacters + dsRevision.Range.Characters.Count
                    Debug.Print sngCharacters
                End If
            Next
            Set pRange = pRange.NextStoryRange
        Loop Until pRange Is Nothing
    Next
End Sub
Reply With Quote