PDA

View Full Version : [SOLVED:] search for specific track change in word



Ethen5155
09-14-2016, 05:06 AM
Hi all,

actually i'm looking for a macro code to look for a specific text in in word and accept its track change

ex.

look for word "Orange" and accept the track change for it.

i only got a code that can accept all track changes in file




Private Sub AcceptAllChanges()
Dim stry As Object


For Each stry In ActiveDocument.StoryRanges
If stry.Revisions.Count >= 1 Then _
stry.Revisions.AcceptAll
Next
End Sub

gmayor
09-14-2016, 06:27 AM
How about

Option Explicit

Private Sub Macro1()
Dim oStory As Range
Dim oRev As Revision
Const strFind As String = "Orange" 'Case sensitive

For Each oStory In ActiveDocument.StoryRanges
If oStory.Revisions.Count >= 1 Then
For Each oRev In oStory.Revisions
If InStr(1, oRev.Range, strFind) > 0 Then
oRev.Accept
End If
Next oRev
End If
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
If oStory.Revisions.Count >= 1 Then
For Each oRev In oStory.Revisions
If InStr(1, oRev.Range, strFind) > 0 Then
oRev.Accept
End If
Next oRev
End If
Wend
End If
Next
lbl_Exit:
Set oStory = Nothing
Set oRev = Nothing
Exit Sub
End Sub

Ethen5155
09-14-2016, 10:38 PM
Works great bro, you are awesome 👍👍

I'm thinking if it is possible to display a msg box to write the wanted text inside it
Better than doing it inside macro code

please don't bother yourself if it can't be done

and thanks again

gmayor
09-15-2016, 06:50 AM
Replace the line

Const strFind As String = "Orange" 'Case sensitive
with

Dim strFind As String

strFind = InputBox("Enter the term to find")
If strFind = "" Then GoTo lbl_Exit