我有一個名爲MainForm的在VBA Excel中傳球變的ByRef 2007
Public increaseArray As Variant
Public countryArray As Variant
然後用戶窗體聲明的公共Variant變量在按鈕點擊的的MainForm子:
Sub testButton_Click()
Dim country As Variant
Set countryArray = Module1.callSomeFunctionThatReturnsVariant(1)
Set increaseArray = Module1.callSomeFunctionThatReturnsVariant(2)
For Each country In countryArray
Call Module1.createPage(country)
Next country
End Sub
在模塊1我有:
Function callSomeFunctionThatReturnsVariant(ByVal testInt As Integer) As Variant
.... do something when testInt = 1
.... do something when testInt = 2
callSomeFunctionThatReturnsVariant = someVariant
End Function
Public Sub createPage(ByVal country As String)
Dim testInt As Integer
... do something
testInt=insertSection(country, MainForm.increaseArray)
End Sub
Function insertSection(ByVal country As String, arr as Variant) As Integer
Dim arrCountry As Variant
For Each arrCountry In arr
If country = "France" Then
...do something
insertSection = 1
Exit Function
End If
Next arrCountry
insertSection = 2
End Function
我路過MainForm.increaseArray
到當得到ByRef參數類型不匹配錯誤功能。我試過使用Function insertSection(ByVal country As String, ByVal arr as Variant) As Integer
但我得到同樣的錯誤。
如果我嘗試從它的getter函數Set testArray = MainForm.getterForIncreaseArray
定義createPage子Dim testArray As Variant
Variant變量,並得到increaseArray我得到類型不匹配的錯誤... 如果我直接傳遞吸氣功能insertSection功能的調用者,我得到ByRef參數類型不匹配...
請幫忙:)
我不認爲一個窗體跌倒的範圍即使它是公開的。 – findwindow
@findwindow,錯了,你明確地可以,只需要聲明爲public,然後用userform的名稱來調用它。至於這個問題,通過參數作爲byref(實際上寫byref,不要懶惰) –
@PatrickLepelletier你有文檔或代碼來證明這一點?我不得不破解我自己的代碼,但如果範圍超出範圍會很好。 – findwindow