lijiao 发表于 2015-8-13 10:37:26

vba提示类型不匹配,如何解决?

运行子程序aaa,到下面红色代码处提示“类型不匹配”,请问如何解决?
Public Declare PtrSafe Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare PtrSafe Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public lTimerID As Integer

Public Sub Start_Timer()

    If lTimerID = 0 Then
      lTimerID = SetTimer(0&, 0&, 3000, AddressOf Ontime)
    Else
      Call Stop_Timer
      lTimerID = SetTimer(0&, 0&, 3000, AddressOf Ontime)
    End If

End Sub

Public Sub Stop_Timer()
    KillTimer 0&, lTimerID
End Sub

Public Sub Ontime()
    Dim R As Integer

   R = MsgBox("ok", vbOKCancel)
   If R = vbCancel And lTimerID <> 0 Then Call Stop_Timer

End Sub

Private Sub aaa()
Call Start_Timer
End Sub

zzyong00 发表于 2015-8-13 12:05:14

Public Declare PtrSafe Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Longptr) As Long
Public Declare PtrSafe Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public lTimerID As Integer

Public Sub Start_Timer()

    If lTimerID = 0 Then
      lTimerID = SetTimer(0&, 0&, 3000, AddressOf Ontime)
    Else
      Call Stop_Timer
      lTimerID = SetTimer(0&, 0&, 3000, AddressOf Ontime)
    End If

End Sub

Public Sub Stop_Timer()
    KillTimer 0&, lTimerID
End Sub

Public Sub Ontime()
    Dim R As Integer

   R = MsgBox("ok", vbOKCancel)
   If R = vbCancel And lTimerID <> 0 Then Call Stop_Timer

End Sub

Private Sub aaa()
Call Start_Timer
End Sub

肖克军 发表于 2015-8-13 15:53:59

帮顶,希望楼主尽快得到解决办法!

lijiao 发表于 2015-8-13 16:28:19

zzyong00 发表于 2015-8-13 12:05 static/image/common/back.gif
Public Declare PtrSafe Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Lon ...

非常感谢
我把long改成any,也通过调试了。
再次感谢!
页: [1]
查看完整版本: vba提示类型不匹配,如何解决?