如何使用VBA仅从ppt中的某些形状导出文本?

如何使用VBA仅从ppt中的某些形状导出文本?,vba,powerpoint,Vba,Powerpoint,我正在尝试从大型ppt导出文本。我已经知道如何导出,但我从所有形状中获取所有文本,并且我只对某些文本感兴趣 是否有一种方法可以让IF函数检查形状的格式,并仅在IF函数为true时获取文本。我只想从带有虚线边框的形状中选择文本。可能吗 这是我的密码 Sub ExportText() Dim oPres As Presentation Dim oSlides As Slides Dim oSld As Slide 'Slide Object Dim oShp

我正在尝试从大型ppt导出文本。我已经知道如何导出,但我从所有形状中获取所有文本,并且我只对某些文本感兴趣

是否有一种方法可以让IF函数检查形状的格式,并仅在IF函数为true时获取文本。我只想从带有虚线边框的形状中选择文本。可能吗

这是我的密码

    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

这是给你的解决方案。有关更多信息,请参阅代码中的注释

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

给你的第一个提示:你已经问了一些问题,有什么好的答案吗?如果是这样的话,您可以接受其中的一些描述