无法在 VBA 中将形状分配给 Class 对象

问题描述 投票:0回答:1

我正在尝试创建一个处理形状(和其他事物)的类。下面是我的类中处理形状的部分(我的类中的每个对象都有一个与之关联的形状,我希望能够在需要时存储和调用它)。 类(CShapes):

Option Explicit
Private m_Shape As Shape

Public Property Get Shape() As Shape

    Set Shape = m_Shape

End Property

Public Property Let Shape(ByVal pShape As Shape)

    Set m_Shape = pShape

End Property

我的功能/方法:

Sub CustomShapes()
    Dim star As New CShapes ' Declare and instantiate the CShapes object
    Dim shp1 As Shape
    Set shp1 = ActiveSheet.Shapes.AddShape(msoShape16pointStar, _
        ActiveCell.Left, ActiveCell.Top, 80, 27)
    Set star.Shape = shp1 ' Set the Shape property of the CShapes object
End Sub

我在“Set star.Shape = shp1”行中收到错误“对象变量或未设置块”。不知道为什么。我怀疑我定义类的方式是错误的?

excel vba visio
1个回答
0
投票

尝试使用 Property Set,而不是 Property Let...

Public Property Set Shape(ByVal pShape As Shape)

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.