Solved

Read Outlook Recurring Appointment Dates

Posted on 2011-02-18
5
364 Views
Last Modified: 2012-05-11
I have a macro that takes the currently selected appointment and places in on certain group members calendars.  It works fine using olItem.Start to get the appointment date on a single appointment.  When it is a recurring appointment, the olItem.Start only get the start date, not the current date of the appointment.
If the original appointment is on 2/18 and I want it to reoccur every Friday on my calendar but only show as a non-recurring appoint on the other users calendars when I click the macro.  It may be 3 Fridays from now before I place the 1 item on their calendars, so I need to loop through the reoccurring dates to get the one I need.
0
Comment
Question by:egalaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 34928303
Hhi, egalaw.

In order to get a specific occurrence of a recurring appointment the code needs to include two additional methods: Sort and IncludeRecurrences.  Something like this.
'Get the items on your calendar'
    Set olkItems = Session.GetDefaultFolder(olFolderCalendar).Items
'Sort the items by start date'
    olkItems.Sort "[Start]"
'Include all occurrences not just the root appointment'
    olkItems.IncludeRecurrences = True
'You are now ready to search for and find the appointment you want'

Open in new window

0
 

Author Comment

by:egalaw
ID: 34928446
The part I am having problems with is looping through the occurrances to find the one within 2 days.
Here is what I have:
    Set olapp = CreateObject("outlook.application")
    Set olSel = olapp.ActiveExplorer.Selection
   
    For Each olItem In olSel
        If olItem.Class = olAppointment Then
                strCalendar = olItem.Organizer
                strSubject = olItem.Subject
                strEvent = strCalendar & ": " & strSubject
                'strEvent = "Office Calendar: " & olItem.Subject
                'strEvent = olItem.Subject
                dteStart = olItem.Start
                dteEnd = olItem.End
    Next
The dteStart is the start of the occurrances.  How do I loop when I get to dteStart = to find the closest date?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34928575
Find the closest day to what?
0
 

Author Comment

by:egalaw
ID: 34928701
I want the date of the occurrance that is within 2 days of the current date
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 34928910
Select one instance of the appointment on your calendar.  Any instance is find.  Then run this macro.
Sub FindNearestRecrringAppt()
    Dim olkItems As Outlook.Items, olkItem As Outlook.AppointmentItem, bolFound As Boolean
    Set olkItem = Application.ActiveExplorer.Selection(1)
    Set olkItems = Application.ActiveExplorer.CurrentFolder.Items.Restrict("[Subject] = '" & olkItem.Subject & "'")
    olkItems.Sort "[Start]"
    olkItems.IncludeRecurrences = True
    For Each olkItem In olkItems
        If Abs(DateDiff("d", Date, olkItem.Start)) <= 2 Then
            MsgBox olkItem.Start
            bolFound = True
            Exit For
        End If
    Next
    If Not bolFound Then msgbox "Could not find an occurrence within 2 days of " & Date
    Set olkItems = Nothing
    Set olkItem = Nothing
End Sub

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question