获取编译错误:参数类型不匹配错误

时间:2017-09-27 04:59:52

标签: vba excel-vba excel

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参数类型不匹配错误

1 个答案:

答案 0 :(得分:6)

定义Dim a, b As String时,b As String只表示 a As Variant。您需要为您定义的每个变量明确定义类型。

将您的行修改为:Dim a As String, b As String,它会起作用。