Office 2010下VBA Addressof的应用
在VBA中Addressof不能在Class或Form中使用,只有Module模式下才能使用Addressof以面是一个计时器的例子:
Form1中代码:
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