【问题标题】:PowerPoint VBA code throws 'Shape Type Mismatch' errorPowerPoint VBA 代码引发“形状类型不匹配”错误
【发布时间】:2014-12-17 08:25:41
【问题描述】:

希望您能提供帮助。以下是应该根据多次发送到过程 x 的形状创建新的 powerpoint 形状的快速子。当我尝试复制原始形状时,第二次出现类型不匹配错误。

Private Sub CreateOneEachPerDP(DPNumber As Integer, OneEach As Powerpoint.Shape)


Dim Count As Integer
Dim NewShape As Powerpoint.Shape
Dim TopOfFirstShape As Integer
Dim SpaceBtwShapes As Integer

For Count = 0 To DPNumber

If Count = 0 Then ' position first shape
'create new shape = OneEach type
Set NewShape = OneEach
    With NewShape
        .Top = TopOfFirstShape
        .Left = 250
    End With
Else ' position further shapes
Set NewShape = OneEach.Duplicate ' GIVES AN ERROR OF TYPE MISMATCH - WHY?
    With NewShape
        .Top = TopOfFirstShape + (Count * SpaceBtwShapes)
        .Left = 250
    End With
End If
'need to size according to text
With NewShape
    .Width = 25
    .Height = 20
End With
'load shape with text (if necessary)
Next Count

pwEnd Sub

【问题讨论】:

  • Duplicate返回类型ShapeRange,而不是Shape,所以不能将其返回值赋给NewShape

标签: vba shapes powerpoint type-mismatch


【解决方案1】:

您可以尝试在 Else 块中进行以下代码修改(它采用 Duplicated Range 对象中的第一个也是唯一一个形状):

Else ' position further shapes
    With OneEach.Duplicate(1)
        .Top = TopOfFirstShape + (Count * SpaceBtwShapes)
        .Left = 250
    End With
End If

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多