Translate

2013年6月20日 星期四

[VBS] Scheduling for running Microsoft Applications(.mdb, .xls, etc)

https://github.com/walter426/VbaUtilities/blob/master/schedule.vbs

Below is an example to do scheduling for running Microsoft Application.
To do scheduling for automation, it is necessary to bypass the error prompt to prevent the application pending.
However, because line label cannot be used in VBS. So actions after error bypassing have to be included in the if brackets which leave bad syntax in the code.

Code:

Option Explicit

'Schdule Task to append Database
Dim fso, oD

Set fso = CreateObject("Scripting.FileSystemObject")
Set oD = fso.GetDrive(fso.GetDriveName(WScript.ScriptFullName))

'Check whether space is enough for appending
If oD.FreeSpace/1024/1024/1024 < 2 then
    WScript.Quit
End If

Dim CurrDir_path
CurrDir_path = fso.GetParentFolderName(Wscript.ScriptFullName)

Dim oAccess
Set oAccess = CreateObject("access.application")

With oAccess
    .Visible = True

On Error Resume Next
    .OpenCurrentDatabase CurrDir_path & "\SampleDb.mdb"
    
If Err.Number = 0 Then
.DoCmd.RunMacro "ScheduleTask"

.CloseCurrentDatabase

End If 'Err.Number = 0

    .Quit

End With 'oAccess

Set oAccess = Nothing


WScript.Quit (0)

沒有留言:

張貼留言