Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting comments from a PowerPoint presentation using VBA

Tags:

powerpoint

vba

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 to 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 image 923
balalakshmi Avatar asked Oct 15 '22 02:10

balalakshmi


1 Answers

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.

like image 126
hol Avatar answered Oct 20 '22 14:10

hol