PDA

View Full Version : Macro to convert text in a certain style to Word comments



aurian
07-18-2012, 03:40 PM
I am trying to write a macro to convert all text with the "UserComment" character style applied, into a MS Word inserted comment.

The macro does a Find, successfully converts the first block of text it encounters into a comment. Then it does create an empty comment for the second block of text it encounters, but it never copies the text into the comment. At this point, Word crashes.

I am running Word 2003 SP3.

Please help!!


Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("UserComment")
While Selection.Find.Execute = True
With Selection.Find
Selection.Cut
Selection.Comments.Add Range:=Selection.Range
Selection.Paste
Selection.EscapeKey
End With
Wend
End Sub



here is the Word crash error from the event log:

Faulting application winword.exe, version 11.0.8169.0, stamp 465f2a40, faulting module winword.exe, version 11.0.8169.0, stamp 465f2a40, debug? 0, fault address 0x000b6988.

gmaxey
07-18-2012, 04:06 PM
Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Style = "UserComment"
While .Execute
oRng.Comments.Add oRng, oRng.Text
oRng.Text = ""
Wend
End With
End Sub