Solved

Read Outlook Recurring Appointment Dates

Posted on 2011-02-18
5
361 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
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now