可以实现的,不仅可以关闭,如果不止1页,还可以像播放幻灯片一样来切换到下一页,最后关闭(只适用简体中文,其它的请自行修改) Option Explicit Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Dim TID As Long Sub doChk() Static totalSecs As Long If pntPreviewHwnd <> 0 Then totalSecs = totalSecs + 200 If totalSecs >= 2000 Then If BIsWindowEnabled = True Then stopChk totalSecs = 0 VBA.SendKeys "%n" InitChk Else stopChk totalSecs = 0 VBA.SendKeys "%c" InitChk End If End If Else totalSecs = 0 End If End Sub Sub InitChk() TID = SetTimer(0, 0, 200, AddressOf doChk) End Sub Sub stopChk() KillTimer 0, TID End Sub Function pntPreviewHwnd() As Long Dim XLhwnd As Long XLhwnd = FindWindow("XLMAIN", Application.Caption) pntPreviewHwnd = FindWindowEx(XLhwnd, 0&, "EXCELC", vbNullString) End Function Function BIsWindowEnabled() As Boolean Dim XLhwnd As Long, pntPreviewHwnd As Long, WindowText As String, pntPreviewHwndButton As Long XLhwnd = FindWindow("XLMAIN", Application.Caption) pntPreviewHwnd = FindWindowEx(XLhwnd, 0&, "EXCELC", vbNullString) BIsWindowEnabled = False pntPreviewHwndButton = FindWindowEx(pntPreviewHwnd, 0&, "Button", vbNullString) Do While pntPreviewHwndButton <> 0 WindowText = String(255, Chr(0)) GetWindowText pntPreviewHwndButton, WindowText, 255 WindowText = Left(WindowText, InStr(WindowText, vbNullChar) - 1) If WindowText = "下一页(&N)" Then If IsWindowEnabled(pntPreviewHwndButton) <> 0 Then BIsWindowEnabled = True Exit Do End If End If pntPreviewHwndButton = FindWindowEx(pntPreviewHwnd, pntPreviewHwndButton, "Button", vbNullString) Loop End Function 见附件(附件为2秒切换一次):
4d6d2uYo.rar
(14.26 KB, 下载次数: 5355)
[此贴子已经被作者于2008-3-5 19:31:43编辑过] |