Thursday, May 26, 2011

Create a reminder- using VBA

This is how you can create reminder in Excel using VBA, these codes helps you to remind when you open your excel workbook
















Y: remind me
N : don't remind me

On VBE (ALT + F11) and in the project explorer window, double click on "ThisWorkbook". Paste the code below.

Private Const reminder As Integer = 1
Private reminderNext As Variant
Public Sub RemindMe()
       currentTime = Time
       nextMin = CDate(Format(Time + 1 / (24 * 60), "hh:mm"))

       myrows = Range("A1").CurrentRegion.Rows.Count

        For thisrow = 2 To myrows
              If (Cells(thisrow, "D") = "X") Then

                    thistime = CDate(CDate(Cells(thisrow, "A")) + Cells(thisrow, "B"))

                   If ((thistime >= Now) And (thistime <= Now + 1 * reminder / (24 * 60))) Then task = task & vbCrLf & Cells(thisrow, "C") & " at " & Format(Cells(thisrow, "B"), "hh:mm")
                  End If
               End If
        Next thisrow
If (task <> "") Then MsgBox task

reminderNext = Now + TimeSerial(0, reminder, 0)
Application.OnTime reminderNext, "ThisWorkbook.remindMe",, True

End Sub


Private Sub Workbook_Open()

Call RemindMe

End Sub

No comments:

Post a Comment