Macro duplicates last comment

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
 
B

Barry Schwarz

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:

snip code

Why not step through the macro in the debugger and see what is
happening?
 
G

Garcia

Why not step through the macro in the debugger and see what is
happening?<<

I have, many times, but I'm afraid my knowledge of VBA is not enough to
understand what is happening, the only thing I see is that the last comment
is inserted twice.

Can you please explain why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top