0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

パワーポイントのVBAでコメントを取得する

Posted at

パワーポイントのVBAでコメントの返信を取得する方法が分からなかったのでその方法です。
エクセルVBAと同じようにできると思い込んで余計な検索をしてしまっていました。

環境

  • パワーポイント2024
  • windows11

コメントを取得

  • 以下でパワーポイントすべてのコメントを取得する
  • これだとコメントへの返信は取得できない
Sub GetAllComments()

    Dim ppt As Presentation
    Dim slide As slide
    Dim comment As comment
    Dim shape As shape
    
    Set ppt = ActivePresentation

    For Each slide In ppt.Slides
        For Each comment In slide.Comments
            Debug.Print "スライド " & slide.SlideIndex & ": " & " - " & comment.Text
        Next
    Next

End Sub

新しいコメント

  • 返信は最近のofficeの機能で新しいコメントというもの
  • エクセルだとCommentThreadedで取得できるようです
  • ただこのオブジェクトはパワーポイントには存在しなかった

xmlファイルから探す

  • pptmをzipにしてxmlファイルを見てみました
  • パワポ.zip > ppt > comments > modernCommentxxxxx.xml
  • このファイルでcmLstの中にreplyLstというのがあり、これが返信の内容になっていました
  • オブジェクトブラウザーで探してみるとcommentのメンバーにRepliesがありました
  • 返信が取得できそうです
  • Comment.Replies プロパティ (PowerPoint)
Property Replies As Comments
    読み取り専用
    PowerPoint.Comment のメンバー

返信Repliesの取得

  • これで返信の内容も取得できました!
  • 返信の返信とかはネストして追加できないようなので、ここまで取得できたら終わり!
  • 検索するとエクセルのCommentThreadedが出てきてRepliesに気付くまで時間がかかりました
Sub GetAllComments()

    Dim ppt As Presentation
    Dim slide As slide
    Dim comment As comment
    Dim shape As shape
    Dim re As comment
    
    Set ppt = ActivePresentation

    For Each slide In ppt.Slides
        For Each comment In slide.Comments
            Debug.Print "スライド " & slide.SlideIndex & ": " & " - " & comment.Text
            For Each re In comment.Replies
                Debug.Print "返信:" & re.Text
            Next
        Next
    Next

End Sub

ハイライトの文字

  • 文字を選択してコメントを入れた時に、そのハイライトされた文字を取得したかった

  • けどこれは簡単にはできないようでした

  • ワードの場合はScopeというので取得できるようでした

  • Comment.Scope プロパティ (Word)

  • PowerPointもXMLファイルからなら取得できるようです

  • comment.xmlファイルのcpとlenからわかるようです

  • コメントがあるshapeの5文字目から4文字分がコメント対象のハイライトされた文字になる

<ac:txMk cp="5" len="4">
<ac:context len="83" hash="1992710558"/>
</ac:txMk>

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?