Skip to main content

Notifications

Community site session details

Community site session details

Session Id : xlafFWRfAX2Rvy/8HrXFOy
Power Automate - AI Builder
Unanswered

extracting author comments in MS word

Like (2) ShareShare
ReportReport
Posted on 7 Jun 2022 16:49:13 by 4

Hi Team

 

I am excited to interact with you to get to know more on Power Automate with AI builder. I would appreciate if you could help me extracting author comments in MS word using Power Automate with AI builder and importing into an excel as classified author comments.

 

Thanks

Ramamurthy Jagannathan

  • Suggested answer
    Covalent Profile Picture
    7 on 14 Mar 2025 at 19:18:28
    extracting author comments in MS word
    Not utilizing power platform, but here's a VBA script you can just load into the word document and it generates an Excel file with all comments. Auto-generated table populates the following attributes of each comment: 
     
    Page Number, Section Number, Section Title, Author's Name, Comment, Referenced Text, Is Reply, Date
     

    Haven't gotten "Is Reply" to work yet but if "Referenced Text" is a duplicate, you know it's a reply.
    The two section columns pull the headers in the doc, if applicable.
     
     
    Sub ExportCommentsToExcel()
        Dim xlApp As Object, xlWB As Object
        Dim i As Integer
        Dim sectionNum As String
        Dim sectionTitle As String
        Dim referencedText As String
        Dim isReply As String ' Store as string (TRUE/FALSE)
        Dim cmtRange As Range
        Dim para As Paragraph
        ' Initialize Excel
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        Set xlWB = xlApp.Workbooks.Add
        With xlWB.Worksheets(1)
            ' Set header values
            .Cells(1, 1).Value = "Page Number"
            .Cells(1, 2).Value = "Section Number"
            .Cells(1, 3).Value = "Section Title"
            .Cells(1, 4).Value = "Author's Name"
            .Cells(1, 5).Value = "Comment"
            .Cells(1, 6).Value = "Referenced Text"
            .Cells(1, 7).Value = "Is Reply"
            .Cells(1, 8).Value = "Date"
            ' Format headers
            With .Range("A1:H1")
                .Font.Bold = True
                .HorizontalAlignment = xlCenter
                .Interior.Color = RGB(191, 191, 191) ' Grey color
                .Borders.Weight = xlThin
                .Borders.LineStyle = xlContinuous
            End With
            ' Populate the data
            For i = 1 To ActiveDocument.Comments.Count
                Set cmtRange = ActiveDocument.Comments(i).Scope
                
                ' Initialize variables
                sectionNum = "N/A"
                sectionTitle = "N/A"
                ' Fix for Referenced Text
                If Len(Trim(cmtRange.Text)) > 1 Then
                    referencedText = Trim(cmtRange.Text)
                Else
                    referencedText = "N/A" ' Handles cases where referenced text is just "/" or blank
                End If
                ' Correctly determine if the comment is a reply
                If ActiveDocument.Comments(i).Parent Is Nothing Then
                    isReply = "FALSE" ' Standalone comment
                Else
                    isReply = "TRUE" ' This comment is a reply
                End If
                ' Find the closest preceding heading
                For Each para In ActiveDocument.Paragraphs
                    If para.Range.Start <= cmtRange.Start And para.Style Like "Heading*" Then
                        ' Get heading title
                        sectionTitle = Trim(para.Range.Text)
                        ' Get heading number (if formatted as a numbered list)
                        On Error Resume Next
                        sectionNum = Trim(para.Range.ListFormat.ListString) ' Extracts the number like "1.2.3"
                        On Error GoTo 0
                    End If
                Next para
                ' Populate Excel rows
                .Cells(i + 1, 1).Value = cmtRange.Information(wdActiveEndPageNumber)
                .Cells(i + 1, 2).Value = sectionNum ' Store only section number
                .Cells(i + 1, 3).Value = sectionTitle ' Store only section title
                .Cells(i + 1, 4).Value = ActiveDocument.Comments(i).Author
                .Cells(i + 1, 5).Value = ActiveDocument.Comments(i).Range.Text
                .Cells(i + 1, 6).Value = referencedText ' Now handles cases where text is blank or just "/"
                .Cells(i + 1, 7).Value = isReply ' Correct TRUE/FALSE reply detection
                .Cells(i + 1, 8).Value = Format(ActiveDocument.Comments(i).Date, "mm/dd/yyyy")
            Next i
            ' AutoFit columns
            .Columns("A:H").AutoFit
        End With
        ' Cleanup
        Set xlWB = Nothing
        Set xlApp = Nothing
    End Sub
  • Suggested answer
    Matkje Profile Picture
    22 on 29 Aug 2024 at 05:33:32
    extracting author comments in MS word
    Hey
     
    You can do it by using basic actions available in Power Automate Desktop. Even though there aren't any built in functions to handle it, you can get it sorted quite easily by saving it as XML :-)
     
     
    Best regards
    Mathias Kjeldsen 
  • _AL_ Profile Picture
    2 on 30 Aug 2023 at 16:05:11
    Re: extracting author comments in MS word

    Building on the query above, it would be amazing to be able to pull comments out of a document and capture not only the attributes that are native to the comment (comment text, author, date, highlighted text, page number), but also better information about where the comment appears in the document.  As a lawyer, I am usually working with contracts.  Those that are drafted by experienced Word users include a numbered headers and subheads that are implemented using styles.  Those that are drafted by less experienced users still have numbering, but it is implemented as you would on a typewriter (i.e., not connected to styles or other numbered list formatting).  It would be amazing to be able to extract comments that included a section reference.  I've seen some attempts at doing this, but non that worked well.  Even though it looks like a structured doc on the page, and feels like a structured document when you start using linked cross-references, my understanding is that there is no hierarchical structure at the XML level (e.g., cross-references are enabled by Word in the background by doing iterative passes through the document and adding randomly-numbered bookmarks wherever styles changes). 

  • srduval Profile Picture
    1,663 Super User 2025 Season 1 on 19 Aug 2022 at 13:47:58
    Re: extracting author comments in MS word

    Looking at this a little more today, by comments I assume you mean the actual comments that are off to the side of the word document. One way you'll be able to do this is by taking the file, and unziping it and then pulling the comments.xml file out from the extracted folder. This link will give you a rough idea of what steps you'll be needing. If it's more than just the author commenting, you'll have to have another step to get the file metadata (I think) will give you the author/created by name. You'll then have to parse author value out of the comments.xml

     

    <?xml version="1.0" encoding="utf-8"?>
    <w:comments xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:comment w:initials="SD" w:author="zxxx" w:date="2022-08-19T07:58:44" w:id="1651651">
    <w:p w:rsidR="1E05sd99" w:rsidRDefault="1E05asd99" w14:paraId="69EE3CF3" w14:textId="0DDEA047">
    <w:pPr>
    <w:pStyle w:val="CommentText" />
    </w:pPr>
    <w:r w:rsidR="1E051199">
    <w:rPr />
    <w:t>creating comments</w:t>
    </w:r>
    <w:r>
    <w:rPr>
    <w:rStyle w:val="CommentReference" />
    </w:rPr>
    <w:annotationRef />
    </w:r>
    </w:p>
    </w:comment>
    <w:comment w:initials="SD" w:author="xxxx" w:date="2022-08-19T08:26:56" w:id="252370751">
    <w:p w:rsidR="10166B43" w:rsidRDefault="10166B43" w14:paraId="46E80C36" w14:textId="5C532590">
    <w:pPr>
    <w:pStyle w:val="CommentText" />
    </w:pPr>
    <w:r w:rsidR="10166B43">
    <w:rPr />
    <w:t>Second Comment</w:t>
    </w:r>
    <w:r>
    <w:rPr>
    <w:rStyle w:val="CommentReference" />
    </w:rPr>
    <w:annotationRef />
    </w:r>
    </w:p>
    </w:comment>
    </w:comments>

  • Antrod Profile Picture
    Moderator on 19 Aug 2022 at 07:31:06
    Re: extracting author comments in MS word

    Hello @Ramamurthy 

     

    Unfortunately it's not possible to use AI Builder in Office documents for now. If you manage to turn your Word into PDF, you will be able to extract information from the file using the AI Builder Document processing model.

     

    Let us know if you have other questions on AI Builder!

  • srduval Profile Picture
    1,663 Super User 2025 Season 1 on 18 Aug 2022 at 17:18:27
    Re: extracting author comments in MS word

    I think you need to look into office scripts action, there is a different board on here regarding ai builder, that they might be able to better advise you 

     

  • Anna Chu Profile Picture
    Microsoft Employee on 18 Aug 2022 at 17:17:57
    Re: extracting author comments in MS word

    Hi @Ramamurthy - this is a great question for the AI Builder community - i will move it there.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started
Loading complete