我有一个名为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