VBA如何从函数

时间:2015-08-23 07:30:29

标签: vba

我创建了一个类模块Rect

Public top As Single

Public left As Single

Public bottom As Single

Public right As Single

Public Sub Class_Initialize()
    Me.top = 0
    Me.bottom = 0
    Me.left = 0
    Me.right = 0
End Sub

用于创建Rect个对象的工厂函数:

Private Function n() As Rect
    Dim r As New Rect
    n = r
End Function

当我调用函数n()时,我得到运行时错误'91'。我不知道出了什么问题......

1 个答案:

答案 0 :(得分:1)

对于对象变量,您需要使用String.prototype.ucwords = function() { return this.replace(/\b\S/g,function(c){ return c.toUpperCase() } } 来分配它们:

Set

参见例如What does the keyword Set actually do in VBA?