开发者

Extracting comments from a PowerPoint presentation using VBA

开发者 https://www.devze.com 2023-01-09 05:22 出处:网络
I have a PowerPoint which contains around 50 slides. Each slide might have 1 or more comments provided by the reviwer (done using insert->comment menu).

I have a PowerPoint which contains around 50 slides. Each slide might have 1 or more comments provided by the reviwer (done using insert->comment menu).

I am trying to get the comments programatically exported into a text file using this VBA code:

    Sub ConvertComments()
    ''# Converts new-style comments to old

        Dim oSl As Slide
        Dim oSlides As Slides
        Dim oCom As Comment

        Set oSlides = ActivePresentation.Slides
        For Each oSl In oSlides
            For Each oCom In oSl.Comments
                ''# write the text to file : (oCom.Text)
                WriteToATextFile oCom.Author, <what needs to come here>, oCom.Text
            Next oCom
        Next oSl
End Sub

In the above code, I need to provide the comment context as well 开发者_StackOverflowto be written to a text file (which line in the slide was selected and commented upon)

Question: Is there any attribute I can use to get this info?


Like this:

Sub ConvertComments()
''# Converts new-style comments to old

    Dim oSl As Slide
    Dim oSlides As Slides
    Dim oCom As Comment
    Dim oShape As Shape


    Open "filename.txt" For Output As 1
    Set oSlides = ActivePresentation.Slides

    Dim myContext As String
    For Each oSl In oSlides
        For Each oCom In oSl.Comments
            myContext = ""
            For ShapeIndex = oCom.Parent.Shapes.Count To 1 Step -1
                myContext = myContext & oCom.Parent.Shapes(ShapeIndex).AlternativeText & " "
            Next
            Write #1, oCom.Author & ";" & myContext & ";" & oCom.Text
        Next oCom
    Next oSl
    Close 1
End Sub

The main part is about the loop thru all shapes parent to the comment.


Don't forget the replies!

Adding to Todd Main's code above:

 Sub ConvertComments()
 ''# Converts new-style comments to old >>> and include the Replies.
 
    Dim oSl As Slide, oSlides As Slides
    Dim oCom As Comment, Reply As Comment
    Dim oShape As Shape    

    Open "filename.txt" For Output As 1
    Set oSlides = ActivePresentation.Slides

    Dim myContext As String
    
    For Each oSl In oSlides
        For Each oCom In oSl.Comments
            
            GoSub WriteComment2File
            
            'Don't forget the replies!
            For Each Reply In oCom.Replies 'NOTE:  Replies are just Comment objects
                GoSub WriteComment2File
            Next Reply
            
        Next oCom
    Next oSl
    Close 1
    
    Exit Sub '________________
    
WriteComment2File:
    myContext = ""
    For ShapeIndex = oCom.Parent.Shapes.Count To 1 Step -1
        myContext = myContext & oCom.Parent.Shapes(ShapeIndex).AlternativeText & " "
    Next
    Write #1, oCom.Author & ";" & myContext & ";" & oCom.Text
    Return
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消