G
Garcia
I have this macro to search for text in double brackets and insert a comment
with that text, the problem is that it inserts the last comment twice, and I
don't know why. Any help would be greatly appreciated. This is the code:
Dim oSearchAgain As Boolean
Selection.HomeKey Unit:=wdStory
Do
With Selection.Find
.ClearFormatting
.Text = "[["
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If Selection.Find.found Then
Selection.Extend
With Selection.Find
.ClearFormatting
.Text = "]]"
.Replacement.Text = ""
.Execute
End With
If Selection.Find.found Then
Selection.Copy
oSearchAgain = True
Else
oSearchAgain = False
End If
Else
oSearchAgain = False
End If
Selection.Comments.Add Range:=Selection.Range
Selection.Paste
ActiveWindow.ActivePane.Close
CommandBars("Reviewing").Visible = False
With Options
.RevisedLinesColor = wdAuto
.CommentsColor = wdBlack
.RevisionsBalloonPrintOrientation =
wdBalloonPrintOrientationPreserve
End With
With ActiveWindow.View
.RevisionsMode = wdBalloonRevisions
End With
Loop While oSearchAgain
End Sub
with that text, the problem is that it inserts the last comment twice, and I
don't know why. Any help would be greatly appreciated. This is the code:
Dim oSearchAgain As Boolean
Selection.HomeKey Unit:=wdStory
Do
With Selection.Find
.ClearFormatting
.Text = "[["
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If Selection.Find.found Then
Selection.Extend
With Selection.Find
.ClearFormatting
.Text = "]]"
.Replacement.Text = ""
.Execute
End With
If Selection.Find.found Then
Selection.Copy
oSearchAgain = True
Else
oSearchAgain = False
End If
Else
oSearchAgain = False
End If
Selection.Comments.Add Range:=Selection.Range
Selection.Paste
ActiveWindow.ActivePane.Close
CommandBars("Reviewing").Visible = False
With Options
.RevisedLinesColor = wdAuto
.CommentsColor = wdBlack
.RevisionsBalloonPrintOrientation =
wdBalloonPrintOrientationPreserve
End With
With ActiveWindow.View
.RevisionsMode = wdBalloonRevisions
End With
Loop While oSearchAgain
End Sub