2、在工程资源管理器中双击“模块1”选项打开宏所在模块的代码窗口,在其中输入代码新建一个名为“计划运行过程”的Sub过程,如图2所示。具体的程序代码如下所示:
Sub计划运行过程(Optional WaitHour As Integer=0,_
Optional WaitMin As Integer=5,Optional WaitSec As Integer=0)
Dim strProcName As String,strScheName As String
Dim NextTime As Variant
strScheName="计划运行过程" '保存本过程的名称
strProcName="创建宏" '保存需运行宏或过程的名称
NextTime=Time+TimeSerial(WaitHour,WaitMin,WaitSec) '设置下一个计划运行时间
Application.OnTime NextTime,strProcName '开始一个新过程运行计划
Application.Run strScheName '计划完成后,重新调用本过程
End Sub