0
我試圖從一個大的ppt文件中導出文本。我已經想出瞭如何導出,但是我得到了所有形狀的所有文本,而且我只對某些文本感興趣。如何使用VBA從ppt中的某些形狀導出文本?
有沒有辦法讓IF函數檢查形狀的格式,只有當IF函數爲真時才抓取文本。我只想從具有虛線邊框的形狀中選擇文本。那可能嗎?
這是我的代碼有
Sub ExportText()
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
iFile = FreeFile 'Get a free file number
Dim PathSep As String
Dim FileNum As Integer
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
FileNum = FreeFile
'Open output file
' NOTE: errors here if file hasn't been saved
Open oPres.Path & PathSep & "AllText.TXT" For Output As FileNum
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
If oShp.Type = msoPlaceholder Then
Select Case oShp.PlaceholderFormat.Type
Case Is = ppPlaceholderTitle, ppPlaceholderCenterTitle
Print #iFile, "Title:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderBody
Print #iFile, "Body:" & vbTab & oShp.TextFrame.TextRange
Case Is = ppPlaceholderSubtitle
Print #iFile, "SubTitle:" & vbTab & oShp.TextFrame.TextRange
Case Else
Print #iFile, "Other Placeholder:" & vbTab & oShp.TextFrame.TextRange
End Select
Else
Print #iFile, vbTab & oShp.TextFrame.TextRange
End If ' msoPlaceholder
End If ' Has text frame/Has text
Next oShp
Next oSld
'Close output file
Close #iFile
End Sub
給你的第一個提示:你已經提出了一些問題,有沒有對你有好處的答案?如果是這樣,你可以接受其中的一些描述[這裏](http://stackoverflow.com/faq#howtoask) – 2013-05-03 09:10:49