我正在尝试将Outlook 2016设置为在启动时打开2个窗口,一个带有邮箱,一个带有选定的特定日历

时间:2019-04-09 16:29:36

标签: vba outlook calendar outlook-vba

我的一位客户要求这样做: 当打开Outlook 2016时,他们希望在启动时打开2个窗口,一个窗口带有邮件,一个窗口带有选定的特定日历。日历是共享的。我找到了一个可以根据需要打开2个窗口的代码,但是我不知道如何设置带有日历的窗口以选择特定的日历。

我试图在互联网上进行研究,找不到任何东西

Private Sub Application_Startup()
Dim xCalendar As Folder
Dim xInbox As Folder
Dim xExplorer As Outlook.Explorer
Dim xWidth, xHeight As Integer
On Error Resume Next
xWidth = Int(GetSystemMetrics32(0) / 4) + 60
xHeight = GetSystemMetrics32(1)
Set xInbox = Outlook.Application.ActiveExplorer.CurrentFolder
xInbox.Display
Set Application.ActiveExplorer.CurrentFolder = xInbox
Set xExplorer = Application.ActiveExplorer
With xExplorer
.WindowState = olNormalWindow
.Top = 0
.Left = 0
.Height = xHeight
.Width = xWidth
End With
Set xCalendar = Outlook.Session.GetDefaultFolder(olFolderCalendar)
xCalendar.Display
 Set xExplorer = Application.ActiveExplorer
 With xExplorer
.WindowState = olNormalWindow
.Top = 0
.Left = xWidth
.Height = xHeight
.Width = xWidth
End With
Set xExplorer = Application.ActiveExplorer
With xExplorer
.WindowState = olNormalWindow
.Top = 0
.Left = xWidth * 2
.Height = xHeight
.Width = xWidth
End With
Set xExplorer = Application.ActiveExplorer
With xExplorer
.WindowState = olNormalWindow
.Top = 0
.Left = xWidth * 3
.Height = xHeight
.Width = xWidth
End With
End Sub

我希望这样:单击以打开Outlook,打开2个窗口,一封普通邮件,其中一个已打开日历并选择了特殊日历

1 个答案:

答案 0 :(得分:0)

这就是您要寻找的。要使用自定义组名,只需相应地设置以下行:

Set objGroup = .Item("group name")

完整代码如下:

Dim WithEvents objPane As NavigationPane

'This goes on ThisOutlookSession
Private Sub Application_Startup()
    Set objPane = Application.ActiveExplorer.NavigationPane

End Sub

Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule)

    Dim objPane As NavigationPane
    Dim objModule As CalendarModule
    Dim objGroup As NavigationGroup
    Dim objNavFolder As NavigationFolder
    Dim objCalendar As Folder
    Dim objFolder As Folder

    Dim i As Integer

    If CurrentModule.NavigationModuleType = olModuleCalendar Then
    Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderCalendar)
    DoEvents

    Set objCalendar = Session.GetDefaultFolder(olFolderCalendar)
    Set objPane = Application.ActiveExplorer.NavigationPane
    Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar)

    With objModule.NavigationGroups
        Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup)

    ' To use a different group
        Set objGroup = .Item("group name")
    End With

    For i = 1 To objGroup.NavigationFolders.Count
        Set objNavFolder = objGroup.NavigationFolders.Item(i)
        Select Case i

        ' Enter the calendar index numbers you want to open
            Case 1, 3, 4
                objNavFolder.IsSelected = True

        ' Set to True to open side by side
                objNavFolder.IsSideBySide = False
            Case Else
                objNavFolder.IsSelected = False
        End Select
    Next

' set the view here

    End If

    Set objPane = Nothing
    Set objModule = Nothing
    Set objGroup = Nothing
    Set objNavFolder = Nothing
    Set objCalendar = Nothing
    Set objFolder = Nothing

End Sub