-2

I wish to create a reminder or an alarm to remind myself of reports due especially with irregular frequency.

Below is the code I wish to call automatically on a day and time I specify. It will pop up a message box and if No is clicked, it will ask again every 10 minutes until Yes is clicked.

ans = Msgbox("Have you submitted the report?",vbYesNo + vbQuestion, "Reminder")

If ans = vbNo then

   Do Until ans = vbYes
      WScript.Sleep 600000 'every 10 minutes, 1 = 1ms
      ans = Msgbox("Have you submitted the report?",vbYesNo + vbQuestion, "Reminder")
   Loop 

End If

WScript.Quit

However, I don't know how to write code to trigger the script? Is there feature in VBScript similar to the event procedure in Excel VBA?

For example, I wish to have something like this:

If Weekday(Date()) = 3 or Weekday(Date()) = 5 And Time() >= TimeValue("3:30pm") then
   'Call the above code
End If

However, the above if statement will not run itself even if the date and time are satisfied...

Additional questions:

If I clicked the No, the message box disappears and will come back in 10 minutes. What if I wish to exit the script before the next message box appears, how to realize this?

And also is there any way to specify the time unit rather than milliseconds for the Sleep method? Many thanks!

Passer-by
  • 71
  • 2
  • 10

1 Answers1

1
SCHTASKS /Create /SC WEEKLY /D MON /TN ReportAlarm /st 16:00 /TR "c:\windows\system32\cmd /c 'Echo Report Time & Pause'"

See schtasks /? for help.

This is how you schedule a task for once a week.

But you can use Windows' Alarms and Clocks with a 30 min snooze which is easier.

Click Start, All Apps, Alarms and Clocks. On the Alarm tab click the big + sign on bottom toolbar. Set alarm to 4pm, Repeats to Monday, and Snooze to 30 mins. Name the Alarm Please Submit Report. Click the floppy icon on bottom toolbar to save.

catcat
  • 131
  • 5
  • This looks promisingly like the right answer. But would you put a link to some documentation so we can verify? – S Meaden Jan 17 '19 at 16:07