Option Explicit
Option Compare Text
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowPos& Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const WM_CLOSE = &H10
Dim MsgForm As Long
Private Sub Form_Load()
Text1.Text = "Microsoft Internet Explorer" '一般IE的JS脚本消息框都是这个标题
Text2.Text = "2000" '每两秒执行一次
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "请输入窗体名", 0, "提示": Exit Sub
If Timer1.Enabled = False Then
Command1.Caption = "开启"
Text1.Enabled = False
Text2.Enabled = False
Timer1.Interval = Val(Text2.Text)
Timer1.Enabled = True
Else
Command1.Caption = "停止"
Text1.Enabled = True
Text2.Enabled = True
Timer1.Interval = Val(Text2.Text)
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Timer()
MsgForm = FindWindow(vbNullString, Text1.Text) '查找窗体标题
If MsgForm > 0 Then
'Call SendMessage(MsgForm, WM_CLOSE, 0, ByVal 0&) '关闭此窗体
SetWindowPos MsgForm, -1, 0, 0, 0, 0, 3 '窗体置前
keybd_event vbKeyReturn, 0, 0, 0 '模拟键按下
keybd_event vbKeyReturn, 0, &H2, 0 '模拟键弹起
End If
End Sub

图片另存为 "xxxxx.rar" .........