Solved

Read Outlook Recurring Appointment Dates

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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