我遍历 Excel 工作表中的信息以在 Outlook 中创建约会。当我将它发送到我的默认文件夹时它正在工作。
我进行了更改以将数据上传到特定文件夹(由同事共享)。
从那时起,当我通过我的代码 F8 时,它会保存正在循环通过的行的约会。但是,当我转到下一行时,新约会会替换旧约会,而不是两者都被保存。
Sub ExportToOutlook
Dim OL as Outlook.Application, Appoint as Outlook.AppointmentItem, ES as Worksheet, _
r as Long, i as Long, WB as ThisWorkook, oFolder as Object, o NameSpace as Namespace
Set WB = ThisWorkbook
Set ES = WB.Sheets("Export Sheet")
r = ES.Cells(Rows.count,1).End(xlUp).Row
Set OL = New Outlook.Application
Set oNameSpace = OL.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetFolderFromID("Insert the ID").Items.Add(olAppointmentItem)
For i = 2 to r
With oFolder
.Subject = ES.Cells(i,1).Value
.Start = ES.Cells(i,2).Value
.End = ES.Cells(i,3).Value
.Location = ES.Cells(i,4).Value
.AllDayEvent = ES.Cells(i,5).Value
.Categories = ES.Cells(i,6).Value & " Category"
.Save
End With
Next i
Set OL = Nothing
End Sub