在Excel VBA中将值从子项传递给函数

我不断得到一个ByRef错误,我似乎无法弄清楚。 代码全部写在同一个模块中。

Sub GetTime(Labelname As Object) Dim Hint, Mint, Sint As Integer Dim time As String Hint = CInt(Hour(Now)) Mint = CInt(Minute(Now)) Sint = CInt(Second(Now)) time = CorrectTime(Hint, Mint, Sint) Private Function CorrectTime(Hours As Integer, Minutes As Integer, Seconds As Integer) As String Dim HS, MS, SS As String If Len(CStr(Hours)) = 1 Then HS = "0" & CStr(Hours) Else HS = CStr(Hours) End If If Len(CStr(Minutes)) = 1 Then MS = "0" & CStr(Minutes) Else MS = CStr(Minutes) End If If Len(CStr(Seconds)) = 1 Then SS = "0" & CStr(Seconds) Else SS = CStr(Seconds) End If CorrectTime = HS & ":" & MS & ":" & SS End Function 

每当我尝试运行代码,它给我一个错误

 time = CorrectTime(Hint, Mint, Sint) 

错误types将是ByRef不匹配。

我没有看到什么可以解决这个问题?

常见疑难杂症: Dim Hint, Mint, Sint As Integer

这里只有Sint是一个整数,另外两个variables没有声明一个types,所以默认为Variant ; 当传递给期望整数的函数时会引发不匹配错误。

纠正:

Dim Hint As Integer, Mint As Integer, Sint As Integer