"Tom van Stiphout" <no************ *@cox.net> schreef in bericht news:23******** *************** *********@4ax.c om...
Here is a code fragment to get you started:
Public Sub ReadOutlook()
Dim olApp As Outlook.Applica tion
Dim olNameSpace As Outlook.NameSpa ce
Dim objCalendarFold er As Outlook.MAPIFol der
Dim objAppointment As Outlook.Appoint mentItem
Set olApp = CreateObject("O utlook.Applicat ion")
olApp.GetNamesp ace("MAPI").Log on "Microsoft Outlook"
Set olNameSpace = olApp.GetNamesp ace("MAPI")
Set objCalendarFold er =
olNameSpace.Get DefaultFolder(o lFolderCalendar )
With objCalendarFold er.Items
Set objAppointment = .GetFirst
While Not objAppointment Is Nothing
Debug.Print "Subject=" & objAppointment. Subject & ",
StartTime=" & objAppointment. Start & ", Duration=" &
objAppointment. Duration
Set objAppointment = .GetNext
Wend
End With
Set objCalendarFold er = Nothing
Set olNameSpace = Nothing
Set olApp = Nothing
End Sub
Also, OutlookSpy is a great tool if you want to know all the details
of the Outlook objects.
-Tom.
Thanks much Tom,
Your code errors at my place (at home) on the line
olApp.GetNamesp ace("MAPI").Log on "Microsoft Outlook"
If I comment this line out the code works.
Yesterday I came as far as this with similar code:
Sub TestAutomationO utlook()
On Error GoTo Err_OutL
Dim i As Integer
Dim objOutlook As Outlook.Applica tion
Dim nms As Outlook.NameSpa ce
Dim fld As Outlook.MAPIFol der
Dim itms As Outlook.Items
Set objOutlook = CreateObject("O utlook.applicat ion")
Set nms = objOutlook.GetN amespace("MAPI" )
Set fld = nms.folders("Pe rsoonlijke mappen").folder s("Agenda")
Set itms = fld.Items
For i = 1 To fld.Items.Count 'This is NOT zero-based ???
If DateValue(fld.I tems(i).Start) = Date Then
Debug.Print fld.Items(i).Su bject & "; " & fld.Items(i).St art & "; " & fld.Items(i).Du ration
End If
Next
CleanUp:
Set itms = Nothing
Set fld = Nothing
Set nms = Nothing
Set objOutlook = Nothing
Exit Sub
Err_OutL:
MsgBox Err & " " & Error$, vbCritical
Resume CleanUp
End Sub
I like your code better (more generic) so I will adapt it and add the DateValue restriction to get only the Items of today.
==> Next hurdle is to get at the shared folders.
Suppose I need the shared calendar for "MeetingRoo m1"
In what way do I need to change the codeline
Set objCalendarFold er =olNameSpace. . . . . . . . ??
Something like
Set objCalendarFold er =olNameSpace("S hared folders").folde rs("MeetingRoom 1") ??
(I can't test shared agenda's here at home, don't have exchange server here)
Thanks,
Arno R