【发布时间】:2015-10-02 22:10:08
【问题描述】:
我想通过 VBA 使用 Excel 文件从当前 Outlook 会话中读取所有可用的非共享日历。
我加载了默认日历:
Set Calendar = outApp.GetNamespace("Mapi").GetDefaultFolder(9)
我似乎通过在 VBA 编辑器的本地变量视图中手动浏览 Outlook 会话对象来找到可用的日历。到达那里的路径(通过所有会话、文件夹和项目层次结构)对于每个用户来说显然是不同的。所以我目前最好的解决方案是爬取整个对象,直到找到一个有效的日历。有更好的解决方案吗?
我的目标是识别当前 Outlook 会话中的所有可用日历,并让用户选择在哪个日历中添加新约会。
我使用以下代码添加约会:
Public Sub AddOutlooktermin(subject As String, _
startDateTime As Date, _
endDateTime As Date, _
body As String, _
location As String, _
allDayEvent As Boolean, _
reminderMinutes As Integer, _
setReminder As Boolean, _
busyStatus As Integer _
)
Dim outApp As Object, apptoutapp As Object
Set outApp = CreateObject("Outlook.Application")
Set apptoutapp = outApp.CreateItem(1) 'olAppointmentItem)
With apptoutapp
.Start = startDateTime
.End = endDateTime
.subject = subject
.body = body
.location = location
.allDayEvent = allDayEvent
.reminderMinutesBeforeStart = reminderMinutes
.ReminderSet = setReminder
.busyStatus = busyStatus
.Categories = "#Urlaub"
.importance = 2
.Save
End With
Set apptoutapp = Nothing
Set outApp = Nothing
End Sub
【问题讨论】:
标签: excel vba outlook calendar