我正在尝试通过Sub在excel-VBA中使用参数创建同一无模式UserForm的多个实例。
我可以使它与我要分配的三个参数中的两个一起使用,但是第三个参数会一直返回
“运行时错误'91':对象变量或未设置块变量”
,我不知道为什么。 我可能没有看到明显的错字,但我确实无法指出问题所在。 这是我的代码:
Sub AskToClose(targetWksht As Worksheet,targetRow As Integer,test As String)
Dim newInstanceOfMe As Object
Set newInstanceOfMe = UserForms.Add("MOVE_TO_CLOSED") 'MOVE_TO_CLOSED is the name of my UserForm
newInstanceOfMe.targetWksht = targetWksht 'If I comment this line it works just fine,otherwise Run-time error 91
newInstanceOfMe.targetRow = targetRow
newInstanceOfMe.test = test
newInstanceOfMe.Show vbModeless
End Sub
_____________________________________________________________________
Sub test()
Dim openWksht As Worksheet
Set openWksht = Worksheets("OPEN WO") 'The worksheet exists and works just fine everywhere else
Call AskToClose(openWksht,2,"test 2")
Call AskToClose(openWksht,3,"test 3")
Call AskToClose(openWksht,4,"test 4")
Set openWksht = Nothing 'I tried to comment this line just in case,same result...
End Sub
_____________________________________________________________________
'My MOVE_TO_CLOSED UserForm parameters
Public targetWksht As Worksheet
Public targetRow As Integer
Public test As String