0

我正在尝试从一个大的 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
4

1 回答 1

2

这里有你的解决方案。请参阅代码中的注释以获取更多信息。

Sub Partial_Solution()
'... your code here

'... your loops start here

    'this way check which DashStyle is in your interest,
    'there are lots of different Dash styles of line
    'then you could remove it
    Debug.Print oShp.Line.DashStyle

    'and this way you can check the style before reading from shape
    'put the result here, like 5 which is msoLineDashDot style
    If oShp.Line.DashStyle = 5 Then

        '... your code here

    End If

'... rest of your code here
End Sub
于 2013-05-03T09:20:29.403 回答