一、加入一个窗体,在窗体内加入若干label控件,以显示时间
二、在宏内复制下面代码:
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
Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim mStop As Boolean, oldtime
Public Sub StopIt()
mStop = True
End Sub
'定时关闭
Sub TimerProc(ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
If mStop = True Then
KillTimer hWnd, 0
Else
With UserForm1
.Label5 = Format(Time, "hh时mm分ss秒") '现在时间
.Label6 = Int(Timer - oldtime) & "秒" '已用时间
End With
End If
End Sub
Public Sub 开始统计()
Dim hwd As Long
UserForm1.Show
hwd = FindWindow(vbNullString, "时间统计")
mStop = False
oldtime = Timer
UserForm1.Label4 = Format(Time, "hh时mm分ss秒") '开始时间
SetTimer hwd, 0, 1000, AddressOf TimerProc
'在此插入你的程序调用.如:call abc()
End Sub
三、运行
在WORD内选择宏"开始统计",运行即可。
停止运行可调用call stopit 过程
Dim ws As ObjectSet ws = CreateObject("wscript.shell")
MyAppID = Shell("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", 1) ' 运行 Word 你的路径自己写
AppActivate MyAppID ' 激活word
Clipboard.SetText "正常"
ws.SendKeys "^v"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)