Option Explicit
Sub data()
Dim a, b As String
a = "demo"
b = "text"
Call getValue(a, b)
End Sub
Sub getValue(a As String, b As String)
Cells(1, 1).Value = a
Cells(1, 2).Value = b
End Sub
我收到编译时错误:上面代码中的byref参数类型不匹配错误
答案 0 :(得分:6)
定义Dim a, b As String
时,b As String
只表示 a As Variant
。您需要为您定义的每个变量明确定义类型。
将您的行修改为:Dim a As String, b As String
,它会起作用。