LoginSignup
13
11

More than 5 years have passed since last update.

PowerPoint内のテキストを取得する

Last updated at Posted at 2015-05-24

やりたいこと

PowerPointの各スライドのテキストを取得する。

ソースコード

下記のコードで取得できる。グループ化されたオブジェクトにも対応。
ただし、グラフには未対応。

Module1.bas

Public Sub FindText3()
    Dim sld As Slide
    Dim sh As Shape
    Dim clm As Column
    Dim cl As Cell
    Dim art As SmartArtNode
    Dim grp As GroupShapes

    For Each sld In ActivePresentation.Slides
        For Each sh In sld.Shapes

            'テキストボックス、プレースホルダ、オートシェイプの場合
            If sh.HasTextFrame Then
                Debug.Print sh.TextFrame.TextRange.text

            '表の場合
            ElseIf sh.HasTable Then
                For Each clm In sh.Table.Columns
                    For Each cl In clm.cells
                        Debug.Print cl.Shape.TextFrame.TextRange.text
                    Next
                Next

            'グラフの場合
            ElseIf sh.HasChart Then
                If sh.Chart.HasTitle Then Debug.Print sh.Chart.Title

            'スマートアートの場合
            ElseIf sh.HasSmartArt Then
                For Each art In sh.SmartArt.Nodes
                    Debug.Print art.TextFrame2.TextRange.text
                Next

            'グループの場合
            ElseIf sh.Type = msoGroup Then
                For Each gsh In sh.GroupItems
                    If gsh.HasTextFrame Then Debug.Print gsh.TextFrame.TextRange.text
                Next

            End If

        Next
    Next
End Sub

参考

下記のコードを参考にしました。

  1. 各スライドに配置されたオートシェイプからテキストを取得するPowerPointマクロ
  2. PPTファイル上の全文字列をExcelに出力するパワポマクロ
13
11
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
13
11