vba - 获取编译错误 : argument type mismatch error

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

最佳答案

当您定义 Dim a, b As String这意味着仅限 b As Stringa As Variant .您需要为您定义的每个变量显式定义类型。

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

关于vba - 获取编译错误 : argument type mismatch error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46439799/

相关文章:

xml - excel:无法保存或导出 xml 数据。此工作簿中的 xml 映射不可导出

python - 使用 tkinter 和 openpyxl 导入 Excel 工作表

Excel VBA "End If without block If"- VBA 错误

vba - 有效隐藏枢轴项目

java - 使用 Apache POI 获取单元格颜色

java - 如何使用 Apache POI 为 .xlsx 文件中的所有单元格将空白返回为 null?

python - xlsxwriter,openpyxl : 'Workbook' object has no attribute 'write'

vba - 设置范围语句错误

excel - VBA:计数出现一对值的次数

vba - 是否可以让输入框需要 5 位数字?