以下代码帮助我解析PPT幻灯片的文本并将其转储到名为Project_SI Feedback_temp_v3.csv的csv文件中。此文件应该是我要转储文本的模板,而此代码打开一个名为Project_SI Feedback_temp_v3.csv的新csv文件,而不是将其写入给定模板。有什么办法可以打开现有文件而不是创建一个新文件吗?
Sub ExportTextToCSV()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSld As Slide 'Slide Object
Dim oShp As Shape 'Shape Object
Dim iFile As Integer 'File handle for output
Dim sTempString As String
Dim PathSep As String
Dim Quote As String
Dim Comma As String
iFile = FreeFile 'Get a free file number
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Quote = Chr$(34)
Comma = ","
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
'Open output file
' NOTE: errors here if original PPT file hasn't been saved
Open oPres.Path & PathSep & "Project_SI Feedback_temp_v3.csv" For Output As iFile
For Each oSld In oSlides 'Loop thru each slide
For Each oShp In oSld.Shapes 'Loop thru each shape on slide
'Check to see if shape has a text frame and text
If oShp.HasTextFrame And oShp.TextFrame.HasText Then
sTempString = sTempString & ",,," & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma
End If
Next oShp
' print the result to file:
Print #iFile, sTempString
sTempString = ""
Next oSld
'Close output file
Close #iFile