Я адаптировал код для импорта данных календаря Outlook в файл Excel.csv.
При импорте следует извлекать поля «Тема», «Дата начала», «Дата окончания» и «Категории» через заданный интервал, который вводится с помощью InputBoxes.
Я пытаюсь получить встречи на целый месяц, я получаю некоторые из них. Некоторые из них не показывают повторения в неделю.
Я пытался изменить код Excel, чтобы скопировать данные из календаря Outlook в пустой файл.
Option Explicit
Sub ListAppointments()
Dim olApp As Object
Dim olNS As Object
Dim olFolder As Object
Dim olApt As Object
Dim NextRow As Long
Dim FromDate As Date
Dim ToDate As Date
FromDate = InputBox("Enter the start date (format: yyyy/mm/dd)")
ToDate = InputBox("Enter the end date(format: yyyy/mm/dd)")
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(9) 'olFolderCalendar
NextRow = 2
With Sheets("Sheet1") 'Change the name of the sheet here
.Range("A1:D1").Value = Array("Subject", "Start Date", "End Date", "Category")
For Each olApt In olFolder.Items
If (olApt.Start >= FromDate And olApt.Start <= ToDate) Then
.Cells(NextRow, "A").Value = olApt.Subject
.Cells(NextRow, "B").Value = CDate(olApt.Start)
.Cells(NextRow, "C").Value = CDate(olApt.End)
.Cells(NextRow, "C").NumberFormat = "dd.mm.yyyy hh:mm"
.Cells(NextRow, "D").Value = olApt.Categories
NextRow = NextRow + 1
Else
End If
Next olApt
.Columns.AutoFit
End With
Set olApt = Nothing
Set olFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
End Sub
Я ожидаю извлечь (скопировать) встречи из календаря в пустой файл Excel за указанный интервал времени.
Я обнаружил, что мне нужно реализовать colItems.IncludeRecurrences = True
, но я не могу понять это.