我正在尝试使用用户在其日历上选择的日期填充 Outlook 日历约会模板的约会开始日期。
有人可以提供 VBA 代码,让我可以确定用户在日历上选择的日期(如果有)吗?
您可能会发现选择Explorer 类的属性很有帮助。它返回一个 Selection 对象,其中包含在资源管理器窗口中选择的一个或多个项目。
但你正在寻找的是选定的开始时间 and 选定的结束时间用于以编程方式复制用户在 Outlook UI 中创建约会的方式的属性。通常,用户在日历视图中选择一个时间范围,然后通过双击所选内容或单击功能区“主页”选项卡中的“新建约会”来创建新约会。利用 CalendarView 对象的这两个属性,您可以通过编程方式获取该视图中任何选择的开始时间和结束时间。
然后,您可以通过编程方式创建 AppointmentItem 对象,将 AppointmentItem 对象的 Start 和 End 属性分别设置为 SelectedStartTime 和 SelectedEndTime 属性,以反映日历视图中的任何用户选择。
如果日历视图中的选择是时间范围而不是项目,则 SelectedStartTime 返回等于选择的开始时间的日期值。
如果在日历视图中选择了一个或多个项目,则 SelectedStartTime 返回一个日期值,该值等于显示日历视图的资源管理器的选择中第一个项目的开始时间。该选择由 Explorer 对象的 Selection 属性指定。例如:
Sub CreateAppointmentUsingSelectedTime()
Dim datStart As Date
Dim datEnd As Date
Dim oView As Outlook.view
Dim oCalView As Outlook.CalendarView
Dim oExpl As Outlook.Explorer
Dim oFolder As Outlook.folder
Dim oAppt As Outlook.AppointmentItem
Const datNull As Date = #1/1/4501#
' Obtain the calendar view using
' Application.ActiveExplorer.CurrentFolder.CurrentView.
' If you use oExpl.CurrentFolder.CurrentView,
' this code will not operate as expected.
Set oExpl = Application.ActiveExplorer
Set oFolder = Application.ActiveExplorer.CurrentFolder
Set oView = oExpl.CurrentView
' Check whether the active explorer is displaying a calendar view.
If oView.ViewType = olCalendarView Then
Set oCalView = oExpl.currentView
' Create the appointment using the values in
' the SelectedStartTime and SelectedEndTime properties as
' appointment start and end times.
datStart = oCalView.SelectedStartTime
datEnd = oCalView.SelectedEndTime
Set oAppt = oFolder.items.Add("IPM.Appointment")
If datStart <> datNull And datEnd <> datNull Then
oAppt.Start = datStart
oAppt.End = datEnd
End If
oAppt.Display
End If
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)