使用VBA从PowerPoint演示文稿中提取注释

6

我有一份包含大约50张幻灯片的PowerPoint文档。每张幻灯片可能会有一个或多个评论,这些评论是由审阅者通过插入 -> 评论菜单添加的。

我正在尝试使用以下VBA代码以编程方式将注释导出到文本文件中:

    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

在上述代码中,我需要提供注释上下文以便写入文本文件(选择了哪行幻灯片并进行了评论)。
问题:有没有可以使用的属性来获取此信息?

“comment context”是什么意思?问题是否也涉及如何在VBA中写入文本文件,还是只涉及“注释上下文”?如果有帮助的话,我可以提供如何编写文本文件的代码,也许如果您澄清“注释上下文”,那么这也将与之相关。 - hol
我的意思是评论上下文如下: 假设幻灯片中有一行文本, 审阅者选择它并单击“插入”->“注释”菜单, 我需要获取被选中并被评论的那行。 - balalakshmi
2个回答

4

像这样:

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

主要部分是遍历所有形状,直到找到与评论相关的父级形状。

有没有办法同时获取幻灯片编号? - Alex
@hol:我尝试了这个解决方案,但是我发现这段代码片段无法识别同一幻灯片中的回复评论。你能帮我获取回复评论吗? - Sivaprasad Km
建议您发布一个新问题。 - hol

0

别忘了回复!

在上面的Todd Main的代码中添加:

 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接