Solved

Read Outlook Recurring Appointment Dates

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Resolve DNS query failed errors for Exchange
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
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 …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 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

22 Experts available now in Live!

Get 1:1 Help Now