あなたの仕事にはVBAをお勧めします。使用方法を学ぶ必要がありますApplication.OnTime
;
必要に応じてこれをトリガーして停止する他のサブシステムが必要です。最初にスケジュールを開始できます。
Public stop_running As Boolean
Public sTime As String
Sub Start(input As String)
stop_running = True 'This controls schedule in Application.Ontime
sTime = input
Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running
End Sub
このマクロの実行を停止したい場合は、このマクロを実行してください。
Sub Rscript()
'runs R script through cmd
If Not stop_running Exit Sub
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 1
Dim errorCode As Integer
Dim path As String
path = "RScript C:\R\myscript.R"
errorCode = shell.Run(path, style, waitTillComplete)
End Sub
あなたはこのようにイミディエイトウィンドウからマクロStart
を呼び出すことができます:
Sub Finish()
stop_running = False 'Set the schedule to false to stop the macro
Application.OnTime TimeValue(sTime), "Rscript", Schedule:=stop_running
End Sub
次にこれはあなたのR-スクリプトを実行するサブある
Call Start(TimeValue("14:00:00 pm"))
そして、あなたのマクロが実行されます午後2時に毎日。
私はそれを介入せずに午後2時に毎日どのように実行するのですか? –
@ScottHorvath答えを更新しました。 – Masoud