PowerPoint VBA代码抛出'Shape Type Mismatch'错误

时间:2014-12-16 22:16:47

标签: vba powerpoint shapes powerpoint-vba type-mismatch

希望你能提供帮助。下面是一个快速子,根据发送到过程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

1 个答案:

答案 0 :(得分:0)

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

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

希望这会有所帮助。