我正在玩調用sub(),但不斷收到「用戶定義類型未定義」錯誤。嘗試使用不同的方法將變量聲明爲數組後,無法弄清楚。想知道關於這個的任何指導:VBA:將自定義類型的變量傳遞給sub()
Public Type Whatever
ppp As String
qqq As Long
rrr As Single
End Type
Sub isthisworking()
Dim thisis() As Whatever
Dim i As Long
Dim athing As Long
For i = 0 To 5
With thisis(i)
.ppp = i & "p"
.qqq = i * 2
.rrr = i^3
End With
athing = 20
beingcalled thisis(), athing
End Sub
Public Sub beingcalled(ByRef thisis() As Whatever, athing As Long)
Dim cycles As Long
cycles = UBound(thisis)
For i = 0 To cycles - 1
With thisis(i)
Debug.Print i & ": " & .ppp & "," & .qqq & "," & .rrr
End With
Next
End Sub
一旦我維'thisis'得當,加上'Next'到你的for循環,並改變調用thisis(),athing'到'被調用this,athing',它沒有問題。 –
謝謝@Johncoleman。顯然不在尺寸之上。或者剪切和粘貼技巧! – user110084
您何時需要實際使用CALL語句?爲什麼在調用函數時需要使用somefunction(var1,var2,...),但爲了sub,省略了括號?他們有沒有需要? – user110084