1. I want the title / subject of every appointment to be prepended with the its time.
  2. I want the title to automatically be updated to correspond to the event's time (If I change the date, so does the title's date).


10:00-12:00 Meeting with Joe
  1. Trying to find a built-in method proved no success. Nothing in the options, settings, rules, I pretty much scouraged the whole interface.
  2. A macro is probably the way to go. My VB is non-existent, though I wouldn't be afraid to learn if some one would post some directing links.
  3. I haven't found any "post" appointment saving event for the calendar through google searching. Is there one I could use to activate a macro afterwards?

Is this even possible??


The following snippet does the job well, wrote it in about 3-4 hours, and was quite a pain to write ;)

Any comments on how to make the code more succinct and better structured are very welcomed.

I left commentes on the parts I thought were a bit unclear for future comers. If you read this and don't understand anything, leave a comment! :)

Dim WithEvents curCal As Items ' set var as the holder of Item events
Public lastSavedAppointmentStart As Date ' variable so we won't infinitely loop when saving Items
Public lastSavedAppointmentEnd As Date
Public justSaved As Boolean

' Some initial Startup Code from slipstick.com
' F5 while the cursor is in this sub (in the vba editor)
' will reload the so called "project"
Private Sub Application_Startup()
   Dim NS As Outlook.NameSpace
   Set NS = Application.GetNamespace("MAPI")
   Set curCal = NS.GetDefaultFolder(olFolderCalendar).Items
   Set NS = Nothing
   lastSavedAppointmentStart = Now()
   lastSavedAppointmentEnd = Now()

End Sub

Private Sub checkPrependtime(ByVal Item As Object)
    Dim isntLastAppt As Boolean
    isntLastAppt = isntLastSavedAppointment(Item)
    If justSaved = False And isntLastAppt Then
        If Not isTimePrepended(Item) Then
            Call saveLastAppointment(Item)
            Call prependTime(Item)
            Call removePrependedTime(Item)
        End If
        justSaved = False
    End If
End Sub

Function isntLastSavedAppointment(ByVal Item As Outlook.AppointmentItem) As Boolean
    isntLastSavedAppointment = lastSavedAppointmentStart <> Item.start Or lastSavedAppointmentEnd <> Item.End
End Function

Private Sub saveLastAppointment(ByVal Item As Outlook.AppointmentItem)
    justSaved = True
    lastSavedAppointmentStart = Item.start
    lastSavedAppointmentEnd = Item.End
End Sub

Private Sub removePrependedTime(ByVal Item As Outlook.AppointmentItem)
    Set lastSavedAppointment = Nothing
    Dim oldSubject As String
    ' Cut out the time part of the subject (e.g. 13:00-15:00 Meeting with Joe)
    ' returns Meeting with Joe
    oldSubject = Mid(Item.Subject, 13, Len(Item.Subject))
    Item.Subject = oldSubject
End Sub

Private Sub prependTime(ByVal appt As Outlook.AppointmentItem)
    Dim newSubject As String, apptStart As Date, apptEnd As Date
    Set lastSavedAppointment = appt
    newSubject = Format(appt.start, "hh:mm") & "-" & Format(appt.End, "hh:mm") & " " & appt.Subject
    appt.Subject = newSubject
End Sub

' Check whether the third char is :
' If time is prepended (e.g. Item.subject is something like
' "12:00-13:00 Meeting with joe" Then third char is always :)
Function isTimePrepended(ByVal Item As Outlook.AppointmentItem) As Boolean
    isTimePrepended = InStr(3, Item.Subject, ":")
End Function

' BEGIN event handlers
Private Sub curCal_ItemAdd(ByVal Item As Object)
    If TypeOf Item Is Outlook.AppointmentItem Then
        Call prependTime(Item)
    End If
End Sub

Private Sub curCal_ItemChange(ByVal Item As Object)
    If TypeOf Item Is Outlook.AppointmentItem Then
        Call checkPrependtime(Item)
    End If
End Sub

' END event handlers

It is possible, at least in OWA and Outlook 2013, possibly Outlook 2010. We have just started playing around with developing outlook apps in the office recently, so unfortunately I cannot provide any code to get you started.

Give this a read: http://msdn.microsoft.com/en-us/library/dn574747%28v=office.15%29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.