Search code examples
autohotkeycomobject

Autohotkey Outlook Calender Search


Im trying to figure out how to search for a specific appointment with Autohotkey based on SubjectName. Right now i have it working to show the latest appointment.

olFolderCalendar := 9   
olFolderContacts := 10 
olAppointmentItem = 1
                        
profileName := "Outlook"
Outlook := ComObjCreate("Outlook.Application")
namespace := Outlook.GetNamespace("MAPI")
namespace.Logon(profileName)  
calendar :=  namespace.GetDefaultFolder(olFolderCalendar)
items := calendar.Items
count := items.Count

msgbox % "calendar items: " count
item := calendar.Items(count)


item1 :=  "subject: " item.Subject . "`n"
item1 .=  "Start: " item.Start . "`n"
item1 .=  "Duration: " item.Duration . "`n"
item1 .=  "Body: " item.Body "`n"
msgbox % "item1" item1

Thanks in advance.


Solution

  • Loop through, looking for it:

    olFolderCalendar := 9   
    olFolderContacts := 10 
    olAppointmentItem = 1
    
    profileName := "Outlook"
    Outlook := ComObjCreate("Outlook.Application")
    namespace := Outlook.GetNamespace("MAPI")
    namespace.Logon(profileName)  
    calendar :=  namespace.GetDefaultFolder(olFolderCalendar)
    items := calendar.Items
    count := items.Count
    
    msgbox % "calendar items: " count
    
    InputBox, testsubj, What Subject?, What Subject?
    Loop {
        item := calendar.Items(count - A_Index + 1)
        subj := item.Subject
        IfEqual, subj, %testsubj%
            break
    }
    
    item1 :=  "subject: " item.Subject . "`n"
    item1 .=  "Start: " item.Start . "`n"
    item1 .=  "Duration: " item.Duration . "`n"
    item1 .=  "Body: " item.Body "`n"
    msgbox % "item1" item1
    

    Hth,