How to Auto Create a New Appointment When an Email Is Flagged in Outlook

Some people desire to automatically or quickly create a new Outlook appointment when they flag an email. This article will introduce an approach to realize it with Outlook VBA.

Sometimes, I may receive an email which mentions an appointment or meeting. But it is just an email instead of a common meeting item in Outlook. In this case, I have to create a new appointment in my Outlook calendar manually. That’s a bit troublesome. So I wish that Outlook can automatically create a new appointment. Nevertheless, Outlook has no native support for us to create a new appointment automatically when we flag an email. Therefore, in order to achieve it, I choose to make use of Outlook VBA. Here are the detailed VBA codes and steps.

Auto Create a New Appointment When an Email Is Flagged

  1. In the first place, switch to “Developer” tab and hit “Visual Basic” button in “Code” group.Visual Basic Button
  2. Then in the new “Microsoft Visual Basic for Applications” window, you need to double click on “ThisOutlookSession” to open this project.
  3. And next copy and paste the following VBA codes into it.
Public WithEvents olItems As Outlook.Items

Private Sub Application_Startup()
    Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olItems_ItemChange(ByVal Item As Object)
    Dim oAppt As AppointmentItem
    Dim strMsg As String
    Dim nRes As Integer
 
    On Error Resume Next
 
    If TypeName(Item) = "MailItem" And Item.IsMarkedAsTask = True Then
       strMsg = "Do you want to create a new appointment"
       nRes = MsgBox(strMsg, vbYesNo + vbQuestion, "Confirm Creating Appointment")
       If nRes = vbYes Then
          Set oAppt = Application.CreateItem(olAppointmentItem)
          With oAppt
               .Subject = "New Appt: " & Item.Subject
               .Location = InputBox("Enter the Location, please.")
               'Type the concrete time, such as "12/29/2015 15:30"
               .Start = InputBox("Enter a specific time (format: MM/DD/YYYY hh:mm), please.")
               .Duration = 120
               .Body = "New Appointment: " & vbCrLf & vbCrLf & Item.Body
               .Attachments.Add Item
               .ReminderSet = True
               .ReminderMinutesBeforeStart = 30
               'Use ".Save" to directly save the new appointment
               .Display
          End With
       End If
 
      'To clear the flag on the email
      'If you want to keep email flagged, remove the following 4 lines
       With Item
            .ClearTaskFlag
            .Save
       End With
    End If
End Sub

Copy the VBA Codes into the ThisOutlookSession

  1. Subsequently, you should use “Digital Certificate for VBA Projects” to create a new certificate and sign the current “ThisOutlookSession” project.Digitally Sign the ThisOutlookSession Project
  2. After that, you can exit the “Visual Basic” window and change macro settings to only permit digitally signed macros.Only Permit Digitally Signed Macros
  3. Eventually, you can have a try.
  • Firstly, pitch on an email and click the “Flag” icon. You will get a prompt, like the following screenshot:Confirm Creating Appointment
  • After selecting “Yes”, you will be required to specify the location and hit “OK” button.Enter the Locatiom
  • Then you need to specify the appointment time.Enter a specific time
  • Finally, after clicking “OK”, a new appointment will open up, shown as the image below:New Appointment

Notes:

  1. In this VBA codes, the reminder is set to 30 minutes by default. You can change it in the codes at will.
  2. The codes set the appointment duration to 120 minutes, namely 2 hours. You can change the “.Duration = 120” line as per your needs.
  3. If you didn’t specify a concrete time, the new appointment will be set to the current date and time by default.
  4. You can add the “.Save” line to save the appointment directly.

Dispose of Outlook Problems

It is known that Outlook can suffer various issues. The worst situation must be Outlook corruptions. If your Outlook file is corrupted and you’ve had a backup in hand, you can easily restore your damaged Outlook data from backups. But if you have no backup, you will need to repair the corrupt Outlook file. In this case, you can use the built-in repair tool, Scapst.exe, or resort to a more experienced tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair SQL Server mdf database problem and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published.