Outlook) (CalendarView.SelectedStartTime 属性

返回一个表示 日历视图 对象中选择的开始时间的 日期 。 此为只读属性。

语法

expressionSelectedStartTime

表达 一个代表 CalendarView 对象的变量。

备注

SelectedStartTimeSelectedEndTime 属性的意图是以编程方式复制用户在 Microsoft Outlook 用户界面中创建约会的方式。 通常,用户在日历视图中选择一个时间范围,然后通过双击所选内容或单击功能区的“开始”选项卡中的“新建约会”来创建新约会。 使用 CalendarView 对象的这两个属性,可以通过编程方式获取该视图中任何选定区域的开始时间和结束时间。 然后,可以以编程方式创建 AppointmentItem 对象,将 AppointmentItem 对象的 StartEnd 属性分别设置为 SelectedStartTimeSelectedEndTime 属性,以反映日历视图中的任何用户选择。

如果在日历视图中的选定时间范围内并不是某一项,则 SelectedStartTime 返回一个 Date 值等于所选内容的开始时间。

如果在日历视图中选择了一个或多个项, SelectedStartTime 返回一个 Date 值等于第一个项目的开始时间在日历视图将显示在资源管理器所选内容。 由 资源管理器 对象的 选定 属性指定该选择。

日历视图 对象上使用此属性,请从 (这可以通过 Application.ActiveExplorer 方法返回) 活动 资源管理器 对象的 CurrentView 属性获取 日历视图 对象。 没有一个已知的问题,在使用 CurrentView 对象的属性的当前 文件夹 (由 Application.ActiveExplorer.CurrentFolder 属性返回) 否则-获取 日历视图 对象上使用此属性。

示例

在 Visual Basic for Applications (VBA) 和 C# 下面的代码示例,显示如何使用活动资源管理器中的日历视图的 SelectedStartTimeSelectedEndTime 属性初始化一个新的约会的开始和结束时间。 下面的代码示例是在 VBA 中。

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

下面的托管代码是使用 C# 编写的。 若要运行需要调入组件对象模型 (COM) 的 .NET Framework 托管代码示例,您必须使用可定义托管接口并将其映射到对象模型类型库中的 COM 对象的互操作程序集。 对于 Outlook,您可以使用 Visual Studio 和 Outlook 主互操作程序集 (PIA)。 在您运行适用于 Outlook 2013 的托管代码示例之前,请确保您已安装了 Outlook 2013 PIA 并且已添加了对 Visual Studio 中的 Microsoft Outlook 15.0 对象库组件的引用。 应使用 Office Developer Tools for Visual Studio) 在 Outlook 外接程序 (类中使用以下代码 ThisAddIn 。 代码中的 应用程序对象必须是由 提供的受信任 Outlook ThisAddIn.Globals对象。 有关使用 Outlook PIA 开发托管 Outlook 解决方案的详细信息,请参阅欢迎使用 MSDN 上的 Outlook 主互操作程序集参考

private void CreateAppointmentUsingSelectedTime() 
{ 
 DateTime dateNull = 
 new DateTime(4501, 1, 1, 0, 0, 0); 
 Outlook.Explorer expl = Application.ActiveExplorer(); 
 Outlook.Folder folder = expl.CurrentFolder as Outlook.Folder; 
 Outlook.View view = expl.CurrentView as Outlook.View; 
 if (view.ViewType == Outlook.OlViewType.olCalendarView) 
 { 
 Outlook.CalendarView calView = view as Outlook.CalendarView; 
 DateTime dateStart = calView.SelectedStartTime; 
 DateTime dateEnd = calView.SelectedEndTime; 
 Outlook.AppointmentItem appt = 
 folder.Items.Add("IPM.Appointment") 
 as Outlook.AppointmentItem; 
 if (dateStart != dateNull && dateEnd != dateNull) 
 { 
 appt.Start = dateStart; 
 appt.End = dateEnd; 
 } 
 appt.Display(false); 
 } 
} 

另请参阅

日历视图对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。