Solved

Read Outlook Recurring Appointment Dates

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

757 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

20 Experts available now in Live!

Get 1:1 Help Now