在VBA中未检测到方程式和图像

时间:2018-10-22 08:08:29

标签: powerpoint-vba equation shapes detect

我正在尝试查找PowerPoint幻灯片上存在的嵌入式文件的类型。如果有简单的excel或visio文件,它将检测到它们。我也有其他嵌入的图像和方程式,但是代码给出了以下错误:

类不支持自动化或不支持预期的接口

下面是代码,错误行是debugprint行。

enter code here

 For Each oSl In ActivePresentation.Slides
    For x = oSl.Shapes.Count To 1 Step -1
            Set oSh = oSl.Shapes(x)
                Select Case oSh.Type
                Case msoChart, msoEmbeddedOLEObject, msoLinkedOLEObject
                Debug.Print "Slide " & i & " has a " & oSh.OLEFormat.Object.Application.Name & " file"

                End Select
    Next
Next

   Result:
   SLIDE(1): "Slide11"
   #1           "Foot Placeholder 1"    Type:=14 (msoPlaceholder)
   #2           "Title 2"     Type:=14 (msoPlaceholder)
   #3           "Object 3"    Type:=7 (msoEmbeddedOLEObject)
   #4           "Object 4"    Type:=7 (msoEmbeddedOLEObject)
   #5           "Object 5"    Type:=7 (msoEmbeddedOLEObject)
   #6           "Object 10"   Type:=7 (msoEmbeddedOLEObject)
   #7           "Object 11"   Type:=7 (msoEmbeddedOLEObject)
   #8           "Object 15"   Type:=7 (msoEmbeddedOLEObject)

   SLIDE(2): "Slide12"
   #1           "Footer Placeholder 1"      Type:=14 (msoPlaceholder)
   #2           "Title 2"     Type:=14 (msoPlaceholder)
   #3           "Object 4"    Type:=7 (msoEmbeddedOLEObject)

1 个答案:

答案 0 :(得分:0)

正如Steve Rindsberg所建议的那样,您应该使用ShapeObject.LinkFormat.SourceFullName。下面将列出所有用于Activepresenation的幻灯片中的所有形状。它应该可以帮助您决定下一步要做什么。

[LinkFormat.SourceFullName] 将在可用时附加。

Option Explicit

Sub ListAllShapesType()
    Dim oSlide As Slide, oShp As Shape, i As Long
    For Each oSlide In ActivePresentation.Slides
        Debug.Print "SLIDE(" & oSlide.SlideIndex & "): """ & oSlide.Name & """"
        i = 1
        For Each oShp In oSlide.Shapes
            Debug.Print " #" & i, """" & oShp.Name & """", "Type:=" & WhatShapeType(oShp)
            i = i + 1
        Next oShp
        Debug.Print
    Next oSlide
End Sub

Function WhatShapeType(ShapeObject As Shape) As String
    Dim sType As String
    On Error Resume Next
    Select Case ShapeObject.Type
        Case msoAutoShape: sType = msoAutoShape & " (msoAutoShape)"
        Case msoCallout: sType = msoCallout & " (msoCallout)"
        Case msoCanvas: sType = msoCanvas & " (msoCanvas)"
        Case msoChart: sType = msoChart & " (msoChart)"
        Case msoComment: sType = msoComment & " (msoComment)"
        Case msoContentApp: sType = msoContentApp & " (msoContentApp)"
        Case msoDiagram: sType = msoDiagram & " (msoDiagram)"
        Case msoEmbeddedOLEObject: sType = msoEmbeddedOLEObject & " (msoEmbeddedOLEObject)"
        Case msoFormControl: sType = msoFormControl & " (msoFormControl)"
        Case msoFreeform: sType = msoFreeform & " (msoFreeform)"
        Case msoGroup: sType = msoGroup & " (msoGroup)"
        Case msoInk: sType = msoInk & " (msoInk)"
        Case msoInkComment: sType = msoInkComment & " (msoInkComment)"
        Case msoLine: sType = msoLine & " (msoLine)"
        Case msoLinkedOLEObject: sType = msoLinkedOLEObject & " (msoLinkedOLEObject)"
        Case msoLinkedPicture: sType = msoLinkedPicture & " (msoLinkedPicture)"
        Case msoMedia: sType = msoMedia & " (msoMedia)"
        Case msoOLEControlObject: sType = msoOLEControlObject & " (msoOLEControlObject)"
        Case msoPicture: sType = msoPicture & " (msoPicture)"
        Case msoPlaceholder: sType = msoPlaceholder & " (msoPlaceholder)"
        Case msoScriptAnchor: sType = msoScriptAnchor & " (msoScriptAnchor)"
        Case msoShapeTypeMixed: sType = msoShapeTypeMixed & " (msoShapeTypeMixed)"
        Case msoSlicer: sType = msoSlicer & " (msoSlicer)"
        Case msoSmartArt: sType = msoSmartArt & " (msoSmartArt)"
        Case msoTable: sType = msoTable & " (msoTable)"
        Case msoTextBox: sType = msoTextBox & " (msoTextBox)"
        Case msoTextEffect: sType = msoTextEffect & " (msoTextEffect)"
        Case msoWebVideo: sType = msoWebVideo & " (msoWebVideo)"
        Case Else: sType = ShapeObject.Type & " (Undocumented type!)"
    End Select
    sType = sType & " [" & ShapeObject.LinkFormat.SourceFullName & "]"
    WhatShapeType = sType
End Function
Option Explicit

Sub ListAllShapesType()
    Dim oSlide As Slide, oShp As Shape, i As Long
    For Each oSlide In ActivePresentation.Slides
        Debug.Print "SLIDE(" & oSlide.SlideIndex & "): """ & oSlide.Name & """"
        i = 1
        For Each oShp In oSlide.Shapes
            Debug.Print " #" & i, """" & oShp.Name & """", "Type:=" & WhatShapeType(oShp)
            i = i + 1
        Next oShp
        Debug.Print
    Next oSlide
End Sub

Function WhatShapeType(ShapeObject As Shape) As String
    Dim sType As String
    On Error Resume Next
    Select Case ShapeObject.Type
        Case msoAutoShape: sType = msoAutoShape & " (msoAutoShape)"
        Case msoCallout: sType = msoCallout & " (msoCallout)"
        Case msoCanvas: sType = msoCanvas & " (msoCanvas)"
        Case msoChart: sType = msoChart & " (msoChart)"
        Case msoComment: sType = msoComment & " (msoComment)"
        Case msoContentApp: sType = msoContentApp & " (msoContentApp)"
        Case msoDiagram: sType = msoDiagram & " (msoDiagram)"
        Case msoEmbeddedOLEObject: sType = msoEmbeddedOLEObject & " (msoEmbeddedOLEObject)"
        Case msoFormControl: sType = msoFormControl & " (msoFormControl)"
        Case msoFreeform: sType = msoFreeform & " (msoFreeform)"
        Case msoGroup: sType = msoGroup & " (msoGroup)"
        Case msoInk: sType = msoInk & " (msoInk)"
        Case msoInkComment: sType = msoInkComment & " (msoInkComment)"
        Case msoLine: sType = msoLine & " (msoLine)"
        Case msoLinkedOLEObject: sType = msoLinkedOLEObject & " (msoLinkedOLEObject)"
        Case msoLinkedPicture: sType = msoLinkedPicture & " (msoLinkedPicture)"
        Case msoMedia: sType = msoMedia & " (msoMedia)"
        Case msoOLEControlObject: sType = msoOLEControlObject & " (msoOLEControlObject)"
        Case msoPicture: sType = msoPicture & " (msoPicture)"
        Case msoPlaceholder: sType = msoPlaceholder & " (msoPlaceholder)"
        Case msoScriptAnchor: sType = msoScriptAnchor & " (msoScriptAnchor)"
        Case msoShapeTypeMixed: sType = msoShapeTypeMixed & " (msoShapeTypeMixed)"
        Case msoSlicer: sType = msoSlicer & " (msoSlicer)"
        Case msoSmartArt: sType = msoSmartArt & " (msoSmartArt)"
        Case msoTable: sType = msoTable & " (msoTable)"
        Case msoTextBox: sType = msoTextBox & " (msoTextBox)"
        Case msoTextEffect: sType = msoTextEffect & " (msoTextEffect)"
        Case msoWebVideo: sType = msoWebVideo & " (msoWebVideo)"
        Case Else: sType = ShapeObject.Type & " (Undocumented type!)"
    End Select
    ' Append the LinkFormat detail if available (errors will not affect output)
    sType = sType & " [" & ShapeObject.LinkFormat.SourceFullName & "]"
    WhatShapeType = sType
End Function