Consulting

Results 1 to 2 of 2

Thread: Macro to convert text in a certain style to Word comments

  1. #1
    VBAX Newbie
    Joined
    Jul 2012
    Posts
    1
    Location

    Macro to convert text in a certain style to Word comments

    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.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    [VBA]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[/VBA]
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •