【问题标题】:How do I export powerpoint slide notes to individual text files?如何将 powerpoint 幻灯片笔记导出到单个文本文件?
【发布时间】:2013-04-07 18:42:12
【问题描述】:

通过一些研究,我在以下网站上发现了这个 VBA 代码: http://www.pptfaq.com/FAQ00481_Export_the_notes_text_of_a_presentation.htm

Sub ExportNotesText()

Dim oSlides As Slides
Dim oSl As Slide
Dim oSh As Shape
Dim strNotesText As String
Dim strFileName As String
Dim intFileNum As Integer
Dim lngReturn As Long

' Get a filename to store the collected text
strFileName = InputBox("Enter the full path and name of file to extract notes text to", "Output file?")

' did user cancel?
If strFileName = "" Then
    Exit Sub
End If

' is the path valid?  crude but effective test:  try to create the file.
intFileNum = FreeFile()
On Error Resume Next
Open strFileName For Output As intFileNum
If Err.Number <> 0 Then     ' we have a problem
    MsgBox "Couldn't create the file: " & strFileName & vbCrLf _
        & "Please try again."
    Exit Sub
End If
Close #intFileNum  ' temporarily

' Get the notes text
Set oSlides = ActivePresentation.Slides
For Each oSl In oSlides
    For Each oSh In oSl.NotesPage.Shapes
    If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
        If oSh.HasTextFrame Then
            If oSh.TextFrame.HasText Then
                strNotesText = strNotesText & "Slide: " & CStr(oSl.SlideIndex) & vbCrLf _
                & oSh.TextFrame.TextRange.Text & vbCrLf & vbCrLf
            End If
        End If
    End If
    Next oSh
Next oSl

' now write the text to file
Open strFileName For Output As intFileNum
Print #intFileNum, strNotesText
Close #intFileNum

' show what we've done
lngReturn = Shell("NOTEPAD.EXE " & strFileName, vbNormalFocus)
End Sub

它本质上是按照幻灯片的时间顺序将 Powerpoint 文件中的所有幻灯片注释导出到一个文本文件中。

是否可以更改代码以将幻灯片注释输出到多个文本文件中?我的意思是,如果 powerpoint 文档中有 4 张幻灯片,我们将导出每张幻灯片的注释,如下所示:

  • slide1notes.txt
  • slide2notes.txt
  • slide3notes.txt
  • slide4notes.txt

非常感谢。

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

    我没有太多时间来做更多的事情,但是:

    Sub TryThis()
    ' Write each slide's notes to a text file
    ' in same directory as presentation itself
    ' Each file is named NNNN_Notes_Slide_xxx
    ' where NNNN is the name of the presentation
    '       xxx is the slide number
    
    Dim oSl As Slide
    Dim oSh As Shape
    Dim strFileName As String
    Dim strNotesText As String
    Dim intFileNum As Integer
    
    ' Get the notes text
    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.NotesPage.Shapes
            If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
                If oSh.HasTextFrame Then
                    If oSh.TextFrame.HasText Then
                        ' now write the text to file
                        strFileName = ActivePresentation.Path _
                            & "\" & ActivePresentation.Name & "_Notes_" _
                            & "Slide_" & CStr(oSl.SlideIndex) _
                            & ".TXT"
                        intFileNum = FreeFile()
                        Open strFileName For Output As intFileNum
                        Print #intFileNum, oSh.TextFrame.TextRange.Text
                        Close #intFileNum
                    End If
                End If
            End If
        Next oSh
    Next oSl
    
    End Sub
    

    【讨论】:

    • 谢谢你,史蒂夫....不幸的是,它并没有奏效。收到一条错误消息:“运行时错误'-2147483640 (80000008)': PlaceholderFormat (unknown member) : Failed.”
    • 按“调试”突出显示这一行: If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
    • 我已经更正了代码中的一个错误.. 添加了 intFileNum = FreeFile() ... 但除此之外它在这里工作正常。您在哪个版本的 PowerPoint 中运行它?这可能是您看到的错误的原因。
    • 我在 Mac 上运行最新的 Powerpoint 2011,但仍然遇到同样的错误。也许解释一下我在做什么:打开 PPT 文件 > 工具 > 宏 > Visual Basic 编辑器 > 插入 > 模块 > 在新窗口中粘贴代码 > 运行 > 上面的错误消息。我做错了吗?
    • “我做错了吗?”使用 Mac PowerPoint。 ;-) 我可以在这里重现问题。这似乎是 Mac 实现中的一个错误;更多测试表明,当它到达笔记页面上的幻灯片编号占位符时,它会失败。所以在顶部添加 On Error Resume Next 然后在抓取文本之前,确保 Err.Number = 0
    【解决方案2】:

    由于 Mac PPT/VBA 存在漏洞,这里有一个适用于 Mac 的新版本。由于我在 PC 上执行此操作并且无法复制/粘贴到 Mac 上/从 Mac 上复制/粘贴,因此我没有在 Mac 上运行代码,但应该没问题:

    Sub TryThis()
    ' Write each slide's notes to a text file
    ' in same directory as presentation itself
    ' Each file is named NNNN_Notes_Slide_xxx
    ' where NNNN is the name of the presentation
    '       xxx is the slide number
    
    Dim oSl As Slide
    Dim oSh As Shape
    Dim strFileName As String
    Dim strNotesText As String
    Dim intFileNum As Integer
    
    ' Since Mac PPT will toss non-fatal errors, just keep moving along:
    On Error Resume Next
    
    ' Get the notes text
    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.NotesPage.Shapes
    
            ' Here's where the error will occur, if any:
            If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
            ' so deal with it if so:
            If Err.Number = 0 Then 
                If oSh.HasTextFrame Then
                    If oSh.TextFrame.HasText Then
                        ' now write the text to file
                        strFileName = ActivePresentation.Path _
                            & "\" & ActivePresentation.Name & "_Notes_" _
                            & "Slide_" & CStr(oSl.SlideIndex) _
                            & ".TXT"
                        intFileNum = FreeFile()
                        Open strFileName For Output As intFileNum
                        Print #intFileNum, oSh.TextFrame.TextRange.Text
                        Close #intFileNum
                    End If  ' HasText
                End If   ' HasTextFrame
            End If  ' Err.Number = 0
            End If  ' PlaceholderType test
        Next oSh
    Next oSl
    
    End Sub
    

    【讨论】:

      【解决方案3】:

      如果有人需要一个 txt 文件中的输出:

      Sub TryThis()
      ' Write each slide's notes to a text file
      ' in same directory as presentation itself
      ' Each file is named NNNN_Notes_Slide_xxx
      ' where NNNN is the name of the presentation
      '       xxx is the slide number
      
      Dim oSl As Slide
      Dim oSh As Shape
      Dim strFileName As String
      Dim strNotesText As String
      Dim intFileNum As Integer
      Dim strLine As String
      Dim strData As String
      
      ' Since Mac PPT will toss non-fatal errors, just keep moving along:
      On Error Resume Next
      
      ' Get the notes text
      For Each oSl In ActivePresentation.Slides
          For Each oSh In oSl.NotesPage.Shapes
      
              ' Here's where the error will occur, if any:
              If oSh.PlaceholderFormat.Type = ppPlaceholderBody Then
              ' so deal with it if so:
              If Err.Number = 0 Then
                  If oSh.HasTextFrame Then
                      If oSh.TextFrame.HasText Then
                          strData = strData + "Folie " & oSl.SlideIndex & vbCrLf & oSh.TextFrame.TextRange.Text & vbCrLf & vbCrLf
                          Close #intFileNum
                      End If  ' HasText
                  End If   ' HasTextFrame
              End If  ' Err.Number = 0
              End If  ' PlaceholderType test
          Next oSh
      Next oSl
      
      ' now write the text to file
      strFileName = ActivePresentation.Path _
      & "\" & ActivePresentation.Name & "_Notes" _
      & ".txt"
      intFileNum = FreeFile()
      Open strFileName For Output As intFileNum
      Print #intFileNum, strData
      Close #intFileNum
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-26
        • 2020-10-14
        • 1970-01-01
        • 2019-11-01
        • 1970-01-01
        • 2015-07-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多