' Listing 12.1 ' A VBA Procedure that Sends an Email Message When Outlook Processes a Reminder ' Private Sub Application_Reminder(ByVal Item As Object) Dim msg As MailItem ' ' Create a new message ' Set msg = Application.CreateItem(olMailItem) ' ' Set up the message with your address and the reminder subject ' msg.To = "youraddress@wherever.com" msg.Subject = Item.Subject msg.Body = "Reminder!" & vbCrLf & vbCrLf ' ' Set up the message body using properties ' appropriate to the different reminder types ' Select Case Item.Class Case olAppointment msg.Body = "Appointment Reminder!" & vbCrLf & vbCrLf & _ "Start: " & Item.Start & vbCrLf & _ "End: " & Item.End & vbCrLf & _ "Location: " & Item.Location & vbCrLf & _ "Appointment Details: " & vbCrLf & Item.Body Case olContact msg.Body = "Contact Reminder!" & vbCrLf & vbCrLf & _ "Contact: " & Item.FullName & vbCrLf & _ "Company: " & Item.CompanyName & vbCrLf & _ "Phone: " & Item.BusinessTelephoneNumber & vbCrLf & _ "E-mail: " & Item.Email1Address & vbCrLf & _ "Contact Details: " & vbCrLf & Item.Body Case olMail msg.Body = "Message Reminder!" & vbCrLf & vbCrLf & _ "Sender: " & Item.SenderName & vbCrLf & _ "E-mail: " & Item.SenderEmailAddress & vbCrLf & _ "Due: " & Item.FlagDueBy & vbCrLf & _ "Flag: " & Item.FlagRequest & vbCrLf & _ "Message Body: " & vbCrLf & Item.Body Case olTask msg.Body = "Task Reminder!" & vbCrLf & vbCrLf & _ "Due: " & Item.DueDate & vbCrLf & _ "Status: " & Item.Status & vbCrLf & _ "Task Details: " & vbCrLf & Item.Body End Select ' ' Send the message ' msg.Send ' ' Release the msg object ' Set msg = Nothing End Sub ' ' Listing 12.2 ' An Event Handler for ItemSend That Prompts You to Save a Copy of an Outgoing Message in the Sent Items Folder ' Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim nResult As Integer ' ' Display the prompt ' nResult = MsgBox("Save this message in Sent Items?", vbSystemModal + vbYesNoCancel) ' ' Check the result ' If nResult = vbCancel Then Cancel = True End If If nResult = vbNo Then ' ' If the user clicked No, don't save the message in Sent Items ' Item.DeleteAfterSubmit = True End If End Sub Private WithEvents myExplorer As Explorer ' Place this statement within the Application_Startup ' event handler (see Listing 12.16). Set myExplorer = Application.ActiveExplorer ' Listing 12.3 ' An Event Handler That Asks the User for a Password Before Switching to the "Confidential" Folder Private Sub myExplorer_BeforeFolderSwitch(ByVal NewFolder As Object,Cancel As Boolean) Dim pwd as String ' ' Are we switching to the "Confidential" folder? ' If NewFolder.Name = "Confidential" Then ' ' If so, ask the user for the password ' pwd = InputBox("Please enter the password for this folder:") ' ' Check the password ' If pwd <> "password" Then ' ' If the password doesn't match, cancel the switch ' Cancel = True End If End If End Sub