A.Gautam
A.Gautam

Reputation: 11

Outlook Macro to get recipients of an appointment

I am trying to get all the recipients "list of people in TO: .. section" of an outlook appointment that I select.

I need the subject and and the recipients of all the selected appointments, I could get the subject but am not able to get the recipients. Below is the code I tried..

Sub testCode()

Dim objItem As Object
Dim objApp As Outlook.Application

Set objApp = Application
Set xlApp = CreateObject("Excel.Application")

xlApp.Application.Visible = True
xlApp.workbooks.Open "C:\data.xlsm"
For i = 1 To 49

    Set objItem = objApp.ActiveExplorer.Selection.Item(i)

    xlApp.Range("A" & i & "").Value = objItem.Subject
    xlApp.Range("B" & i & "").Value = objItem.To  // not working

Next i
End Sub 

Upvotes: 1

Views: 2378

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

Use the AppointmentItem.Recipients collection and loop through all recipients. Recipient.Type = olTo are required, olCC - optional, olBCC - resources.

Upvotes: 1

OpiesDad
OpiesDad

Reputation: 3435

There is no To field in an appointment. There are required attendees and optional attendees.

Use these properties:

objItem.OptionalAttendees

and

objItem.RequiredAttendees

As a sidenote, the easiest way to figure out things like this is to examine the object in the locals window of the code window while stepping through the code. This way you can see all of the properties that the object has and figure out what to use.

Upvotes: 2

Related Questions