Outlook/VBA:获取当前视图';开始和结束日期

Outlook/VBA:获取当前视图';开始和结束日期,vba,outlook,Vba,Outlook,我已经为各种Office应用程序编写了VBA,但我对Outlook还不熟悉,所以我仍在学习各种Outlook对象 在Outlook日历视图中,我处于“日”、“工作周”、“周”、“月”或“日程视图”安排中。我可以在这两者之间切换,但我希望看到我的活动。今天是2016年11月29日,显示在我的日历(Outlook 2016)上方,我看到: 日期:“2016年11月29日” 工作周:“2016年11月28日至12月2日” 周:“2016年11月26日至12月2日” 等等 这显然是我当前视图的日期范

我已经为各种Office应用程序编写了VBA,但我对Outlook还不熟悉,所以我仍在学习各种Outlook对象

在Outlook日历视图中,我处于“日”、“工作周”、“周”、“月”或“日程视图”安排中。我可以在这两者之间切换,但我希望看到我的活动。今天是2016年11月29日,显示在我的日历(Outlook 2016)上方,我看到:

  • 日期:“2016年11月29日”
  • 工作周:“2016年11月28日至12月2日”
  • :“2016年11月26日至12月2日”
  • 等等
这显然是我当前视图的日期范围(可能是不正确的术语)

如何在VBA中引用此视图的开始和/或结束日期?我想澄清的是,我不想要选择的开始和结束日期(这是我在网上找到的),而是实际视图的开始和结束日期——我现在在Outlook客户端应用程序上看到的


提前感谢您的时间和帮助。

您需要
CalendarView.DisplayDates
属性。这是一个数组,包含显示的每个日期。获取数组中的第一个和最后一个值。看

为清晰起见,代码复制和修改如下:

Sub DisplayDayRange()

 Dim objView As CalendarView
 Dim varArray As Variant
 Dim beginDate As Date
 Dim endDate As Date

    ' Check if the current view is a calendar view.

    If Application.ActiveExplorer.CurrentView.ViewType = olCalendarView Then       

        ' Obtain a CalendarView object reference for the     
        ' current calendar view.

        Set objView = Application.ActiveExplorer.CurrentView

        ' Obtain the DisplayedDates value, a string  
        ' array of dates representing the dates displayed           
        ' in the calendar view.

        varArray = objView.DisplayedDates

        ' If the example obtained a valid array, display  
        ' a dialog box with a summary of its contents.

        If IsArray(varArray) Then

            beginDate = varArray(LBound(varArray))
            endDate = varArray(UBound(varArray))
            MsgBox "There are " & (UBound(varArray) - LBound(varArray)) + 1 & " days displayed, from " & beginDate & " to " & endDate  
        End If     
    End If

 End Sub