我正在尝试通过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 …Run Code Online (Sandbox Code Playgroud)