使用 TextRange.InsertAfter 方法将文本添加到 VBA 导出的文本文件

Add text to VBA exported text file using TextRange.InsertAfter method

我正在尝试使用 this VBA. In each exported text file I want to add an extra piece of text at the end of the text within the file that is exported. Its seems this is possible with the TextRange.InsertAfter method 从 PowerPoint 将笔记导出到文本文件,但我不确定该怎么做。

假设我想在文件中每个文本范围末尾添加的文本是“额外文本”,我认为这样的方法可能有效

原始

Print #intFileNum, oSh.TextFrame.TextRange.Text

修订

Print #intFileNum, oSh.TextFrame.TextRange.InsertAfter "extra text".Text

可惜没有..

这是VBA

Sub TryThis()
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.InsertAfter "extra text".Text
                    Close #intFileNum
                End If
            End If
        End If
    Next oSh
Next oSl

End Sub

好的,我解决了。这会将文本添加到每张幻灯片,导出为 TXT,然后从幻灯片中删除文本

oSh.TextFrame.TextRange.InsertAfter "extra text"
Print #intFileNum, oSh.TextFrame.TextRange.Text
oSh.TextFrame.TextRange.Replace FindWhat:="extra text", ReplaceWhat:=""