Materi Perkuliahan
Aplikasi media matematika dengan waktu menggunakan VBA for Excel
The procedures to be entered in a Standard Module:
Public dTime As Date
______________________
Sub SetReminder()
‘This Application.OnTime procedure sets reminders at specific times and auto-closes workbook at a specified time:
On Error Resume Next
dTime = Now + TimeValue(“00:00:01”)
‘procedure named SetReminder will autmatically run, at the sheduled time interval, with the OnTime Method.
Application.OnTime dTime, “SetReminder”
‘Close the workbook at the specified time:
If Time = TimeSerial(18, 30, 0) Then
CloseWorkBook
End If
‘set OfficeClose reminder:
If Time = TimeSerial(17, 30, 0) Then
Application.OnTime dTime, “OfficeClose”
End If
‘set LunchBreak reminder:
If Time = TimeSerial(13, 0, 0) Then
Application.OnTime dTime, “LunchBreak”
End If
‘set CoffeeBreak reminder:
If Time = TimeSerial(11, 15, 0) Then
Application.OnTime dTime, “CoffeeBreak”
End If
End Sub
Sub CoffeeBreak()
Dim obj As Object
Dim strMsg As String
Set obj = CreateObject(“WScript.Shell”)
‘play the Beep sound, you can customize the sound / message you wish to play:
Beep
‘the Popup Message Box will automatically close by itself, without user action of clicking Ok:
strMsg = obj.Popup(“Coffee Break Sir!”, vbOKCancel)
End Sub
Sub LunchBreak()
Dim obj As Object
Dim strMsg As String
Set obj = CreateObject(“WScript.Shell”)
Beep
strMsg = obj.Popup(“Lunch Break Sir!”, vbOKCancel)
End Sub
Sub OfficeClose()
Dim obj As Object
Dim strMsg As String
Set obj = CreateObject(“WScript.Shell”)
Beep
strMsg = obj.Popup(“Office Closing Sir!”, vbOKCancel)
End Sub
Sub StopSetReminder()
‘Stop the Application.OnTime procedure named SetReminder
Application.OnTime dTime, “SetReminder”, , False
End Sub
Sub CloseWorkBook()
‘close the workbook
On Error Resume Next
‘call StopSetReminder procedure to stop the Application.OnTime:
StopSetReminder
‘save workbook before closing:
ThisWorkbook.Save
‘close workbook:
ThisWorkbook.Close
End Sub