当前位置: 代码迷 >> VBA >> Office 2010上VBA Addressof的应用
  详细解决方案

Office 2010上VBA Addressof的应用

热度:8542   发布时间:2013-02-26 00:00:00.0
Office 2010下VBA Addressof的应用

在VBA中Addressof不能在Class或Form中使用,只有Module模式下才能使用Addressof以面是一个计时器的例子:

Form1中代码:

Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As LongPrivate Sub CommandButton1_Click()    Module1.testEnd SubPrivate Sub CommandButton2_Click()    KillTimer 0, Module1.mHandleEnd Sub

Module1下代码:

Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As LongPublic mHandle As LongPublic Sub test()    mHandle = SetTimer(0, 0, 2000, AddressOf MyTimerProce)End SubPublic Sub MyTimerProce(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)    MsgBox "hello"End Sub


  相关解决方案