I was on Twitter last night looking for tweets about Outlook when I stumbled across this one.
Here’s my reply and Jake’s follow-up.
Creating some reminders is easy enough so I put a solution together for Jake. Here’s how it works.
When Jake runs the macro it will prompt him for the name of a client. Once he enters that the macro will create the three reminders Jake wants. The macro includes options allowing Jake to control the type of reminder (task or calendar event), the reminder’s subject line, the category the reminders will belong to (Jake can color code them if he wants), the number of minutes before the event’s start time to show the reminder (if Jake sets the type to Event), the time to display the reminders (if Jake set the type to Task), and the length of the event on the calendar (if Jake sets the type to Event).
Adding the code to Outlook.
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
- Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as desired. I included a comment wherever something can be changed.
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
Sub CreateReminders()
'--> Create some constants
'On the next line set the reminder type to either Event (to put the reminders on your calendar) or Task (to add the reminders to your task list).
Const REM_TYPE = "Task"
'On the next line edit the default reminder subject line. The client's name will be appended to the subject.
Const REM_SUBJECT = "Call Client - "
'On the next line edit the name of the category to be assigned to all reminders
Const REM_CATEGORY = "Client Calls"
'On the next line edit the number of minutes before the start of the of the appointment to show the reminder. Only used if REM_TYPE is set to Event.
Const REM_MINUTES = 5
'On the next line edit the time reminders will be shown. Only used if the REM_TYPE is set to Task.
Const REM_TIME = #9:00:00 AM#
'On the next line edit the default length of the appointment in minutes. Only used if the REM_TYPE is set to Event.
Const REM_DURATION = 15
Const SCRIPT_NAME = "Create Reminders"
'--> Create some variables
Dim olkApt As Outlook.AppointmentItem, olkTsk As Outlook.TaskItem, strClient As String, intCnt As Integer, bolCreated As Boolean
'--> Initialize some variables
bolCreated = True
'--> Main routine
'Get the client's name.
strClient = InputBox("Enter the name of the client to contact.", SCRIPT_NAME)
'Was a name entered?
If strClient = "" Then
'No
MsgBox "Operation cancelled. You must enter a client's name for this macro to work.", vbCritical + vbOKOnly, SCRIPT_NAME
Else
'Yes
'Create the three reminders: 14 days, 1 month, and 3 months
For intCnt = 1 To 3
Select Case REM_TYPE
'Create events
Case "Event"
Set olkApt = Application.CreateItem(olAppointmentItem)
olkApt.Subject = REM_SUBJECT & strClient
Select Case intCnt
Case 1
olkApt.Start = DateAdd("d", 14, Date) & " " & REM_TIME
Case 2
olkApt.Start = DateAdd("m", 1, Date) & " " & REM_TIME
Case 3
olkApt.Start = DateAdd("m", 3, Date) & " " & REM_TIME
End Select
olkApt.Duration = REM_DURATION
olkApt.ReminderSet = True
olkApt.ReminderMinutesBeforeStart = REM_MINUTES
olkApt.Categories = REM_CATEGORY
olkApt.Save
'Create tasks
Case "Task"
Set olkTsk = Application.CreateItem(olTaskItem)
olkTsk.Subject = REM_SUBJECT & strClient
Select Case intCnt
Case 1
olkTsk.DueDate = DateAdd("d", 14, Now)
Case 2
olkTsk.DueDate = DateAdd("m", 1, Now)
Case 3
olkTsk.DueDate = DateAdd("m", 3, Now)
End Select
olkTsk.ReminderSet = True
olkTsk.ReminderTime = olkTsk.DueDate & " " & REM_TIME
olkTsk.Categories = REM_CATEGORY
olkTsk.Save
'REM_TYPE has an invalid value
Case Else
bolCreated = False
Exit For
End Select
Next
If bolCreated Then
MsgBox "I created the reminders.", vbInformation + vbOKOnly, SCRIPT_NAME
Else
MsgBox "Operation cancelled. The reminder type is invalid. Valid types are 'Event' and 'Task'.", vbCritical + vbOKOnly, SCRIPT_NAME
End If
End If
'--> Clean up
Set olkApt = Nothing
Set olkTsk = Nothing
End Sub
Adding Buttons to Run the Macro with a Single Click
If Jake wants to run the macro with a single click, then he’ll need to add a toolbar button in Outlook 2007 or a button on the Quick Access Toolbar (QAT) for Outlook 2010.
Outlook 2007. Follow these instructions to add a toolbar button that runs the macro.
Outlook 2010. Follow these instructions to add the macro to the QAT.