1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Private Sub Outlook_Vba_Get_Calendar_Item_Appoinments()
Dim oWorkbook As Workbook, Calendar_To_Excel_File As String
Dim oOutlook_Calendar As Outlook.Folder, oCalendar_Items As Outlook.Items
Dim oCalendarAppointment As Outlook.AppointmentItem
Dim iRow As Double
iRow = 1
'Change path of the Target File name if required
Calendar_To_Excel_File = "C:\Users\xxxxxx\Desktop\En cours\FDGCTA\test.csv"
'Check if Output File already exists
If VBA.Dir(Calendar_To_Excel_File) = "" Then
'To Create New Workbook
Set oWorkbook = Workbooks.Add
oWorkbook.SaveAs Calendar_To_Excel_File
Else
'To Refer Already Created Workbook
Set oWorkbook = Workbooks.Open(Calendar_To_Excel_File)
End If
'Get object reference for Outlook Calendar folder
Set oOutlook_Calendar = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
Set oCalendar_Items = oOutlook_Calendar.Items
'Loop Thru Each Items in Outlook Calendar
For Each oCalendarAppointment In oCalendar_Items
oWorkbook.Sheets(1).Cells(iRow, 1) = oOutlook_Calendar.FolderPath
oWorkbook.Sheets(1).Cells(iRow, 2) = oCalendarAppointment.Start
oWorkbook.Sheets(1).Cells(iRow, 3) = oCalendarAppointment.End
oWorkbook.Sheets(1).Cells(iRow, 4) = oCalendarAppointment.Subject
oWorkbook.Sheets(1).Cells(iRow, 5) = oCalendarAppointment.Location
oWorkbook.Sheets(1).Cells(iRow, 6) = oCalendarAppointment.Duration
oWorkbook.Sheets(1).Cells(iRow, 7) = oCalendarAppointment.Size
'oWorkbook.Sheets(1).Cells(irow, 8) = oCalendarAppointment.Body
iRow = iRow + 1
Next
'Save Excel Workbook With Calendar Appointments
oWorkbook.Save
oWorkbook.Close False 'Close Workbook without any Warning
MsgBox "Outlook Calendar Appointments Downloaded To:" & Calendar_To_Excel_File
End Sub |
Partager