VBA - Compile error: wrong number of arguments
VBA - Compile error: wrong number of arguments
不是我的代码,而是一位同事寻求有关他的宏的帮助。他收到“编译错误:参数数量错误或 属性 赋值无效。”在 Round()
函数上。
这是他的违规代码:
Sub test()
starttime = Timer()
'Processing here
endtime = Timer()
minutes = CInt((endtime - starttime) / 60)
If minutes > CInt((endtime - starttime) / 60) Then
seconds = Round((endtime - starttime) - ((minutes - 1) * 60), 2) 'Error is on this line
minutes = minutes - 1
Else
seconds = Round(((endtime - starttime)) - (minutes * 60), 2) 'Error is on this line too
End If
MsgBox "Total Run Time: " & minutes & " minutes " & seconds & " seconds"
End Sub
它适用于我和他的所有同事。我让他切换到 Application.WorksheetFunction.Round()
并且效果很好。他在 Tools > References 中选择了相同的模块。变量未在代码中定义,因此应该使用 Variant 然后设置为 Integer 或 Single 在 运行 时间。我想我一直试图让他定义变量,但我们遇到了同样的错误。
知道为什么 Round()
只对他造成错误吗?
@BigBen 做对了。我让我的同事在他的 VBA 项目中搜索“Round”,他发现他有一个名为 Round 的子程序。我告诉他这个名字不好,他应该改个名字!
不是我的代码,而是一位同事寻求有关他的宏的帮助。他收到“编译错误:参数数量错误或 属性 赋值无效。”在 Round()
函数上。
这是他的违规代码:
Sub test()
starttime = Timer()
'Processing here
endtime = Timer()
minutes = CInt((endtime - starttime) / 60)
If minutes > CInt((endtime - starttime) / 60) Then
seconds = Round((endtime - starttime) - ((minutes - 1) * 60), 2) 'Error is on this line
minutes = minutes - 1
Else
seconds = Round(((endtime - starttime)) - (minutes * 60), 2) 'Error is on this line too
End If
MsgBox "Total Run Time: " & minutes & " minutes " & seconds & " seconds"
End Sub
它适用于我和他的所有同事。我让他切换到 Application.WorksheetFunction.Round()
并且效果很好。他在 Tools > References 中选择了相同的模块。变量未在代码中定义,因此应该使用 Variant 然后设置为 Integer 或 Single 在 运行 时间。我想我一直试图让他定义变量,但我们遇到了同样的错误。
知道为什么 Round()
只对他造成错误吗?
@BigBen 做对了。我让我的同事在他的 VBA 项目中搜索“Round”,他发现他有一个名为 Round 的子程序。我告诉他这个名字不好,他应该改个名字!