香港新浪網 MySinaBlog
« 上一篇 | 下一篇 »
Emily | 31st Aug 2006, 00:29 AM | API / Add-in | (2584 Reads)

INPUTBOX 延遲默認輸入

Excel Home 原問題

我的要求是彈出INPUTBOX窗口(此時是空文本框)後,停頓5秒鍾,自動鍵入123。

用SendKeys 的方法, 比較簡單易懂

'---------------------------------------------------------------------------------------
' Module    : Module1
' DateTime  : 30/8/2006 01:03
' Author    :
' Purpose   :
'---------------------------------------------------------------------------------------
' Base on chijanzen's code
' Modified by stanleypan
'

Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long,  ByVal uElaspe As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Dim TID As Long
Const Sec = 5   ' seconds

Sub Test()
   TID = SetTimer(0, 0, Sec * 1000, AddressOf CloseTest)
   s = InputBox("Please Enter a nubmer" & Chr(13) & Sec & "  Seconds Auto Input", "Information", "")
   KillTimer 0, TID
   MsgBox s
End Sub

Sub CloseTest()
   Application.SendKeys "123", True
   KillTimer 0, TID
End Sub

... 

參考 INPUTBOX 延遲輸入的方法研究:

用HOOK+SendMessage 的技術,可以得到INPUTBOX 窗體的句柄

http://club.excelhome.net/dispbbs.asp?boardID=31&ID=185695&page=1&px=0