CalendarView.SelectedEndTime プロパティ (Outlook)

CalendarView オブジェクトの選択範囲の終了時間を表す日付型 ( Date ) の値を返します。 値の取得のみ可能です。

構文

SelectedEndTime

CalendarView オブジェクトを表す変数。

注釈

SelectedStartTime プロパティと SelectedEndTime プロパティの目的は、ユーザーが Microsoft Outlook ユーザー インターフェイスで予定を作成する方法をプログラムでレプリケートすることです。 通常、ユーザーは予定表ビューで時間範囲を選択し、選択内容をダブルクリックするか、リボンの [ホーム] タブで [新しい予定] をクリックして、新しい予定を作成します。 CalendarView オブジェクトのこの 2 つのプロパティを使用すると、そのビューの選択範囲の開始時刻と終了時刻をプログラムによって取得できます。 その後、AppointmentItem オブジェクトをプログラムで作成し、AppointmentItem オブジェクトの Start プロパティと End プロパティをそれぞれ SelectedStartTime プロパティと SelectedEndTime プロパティに設定して、予定表ビューでユーザーの選択を反映できます。

[予定表] ビューの選択範囲がアイテムではなく時間範囲の場合、 SelectedEndTime は選択範囲の終了時刻と同じ Date 値を返します。

[予定表] ビューで 1 つ以上のアイテムが選択されると、 SelectedEndTime は、[予定表] ビューを表示するエクスプローラーの選択範囲内の最初のアイテムの終了時刻と同等の Date 値を返します。 この選択範囲は、 Explorer オブジェクトの Selection プロパティにより示されます。

このプロパティを CalendarView オブジェクトで使用するには、アクティブな Explorer オブジェクト ( Application.ActiveExplorer メソッドで取得) の CurrentView プロパティから CalendarView オブジェクトを取得します。 Application.ActiveExplorer.CurrentFolder プロパティから取得される現在の Folder オブジェクトの CurrentView プロパティを使用して取得した CalendarView オブジェクトに対してこのプロパティを使用すると、問題が発生することがわかっています。

次の使用例は、Visual Basic for Applications (VBA) および C# において、アクティブなエクスプローラーのカレンダー ビューの SelectedStartTime プロパティと SelectedEndTime プロパティを使用して、新しい予定の開始時間と終了時間を初期化する方法を示します。 次は、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 オブジェクト ライブラリ コンポーネントへの参照を追加していることを確認してください。 Outlook アドインのクラスで次のコードを ThisAddIn 使用する必要があります (Office Developer Tools for Visual Studio を使用)。 コードの Application オブジェクトは で提供された、信頼済み 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); 
 } 
} 

関連項目

CalendarView オブジェクト

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。