Skip to main content

如何在啟動 Outlook 時自動打開多個 Outlook 窗口?

Author: Xiaoyang Last Modified: 2025-05-12

當您啟動 Outlook 帳號時,郵件窗口會正常打開。是否可以在啟動 Outlook 的同時自動打開其他 Outlook 窗口,例如郵件、日曆、聯絡人和任務窗口呢?

使用 VBA 代碼在啟動 Outlook 時自動打開多個 Outlook 窗口


使用 VBA 代碼在啟動 Outlook 時自動打開多個 Outlook 窗口

在此,我可以介紹一段 VBA 代碼,幫助您在啟動 Outlook 時立即打開多個 Outlook 窗口,例如郵件、日曆、聯絡人和任務窗口。請按照以下步驟操作:

1. 按住 ALT + F11 鍵以打開 Microsoft Visual Basic for Applications 窗口。

2. 在 Microsoft Visual Basic for Applications 窗口中,雙擊 Project1(VbaProject.OTM) 窗格中的 ThisOutlookSession 以打開模組,然後將以下代碼複製並粘貼到空白模組中。

VBA 代碼:在啟動 Outlook 時自動打開多個 Outlook 窗口:

Private Sub Application_Startup()
Dim xCalendar As Folder
Dim xTasks As Folder
Dim xContacts 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 xContacts = Outlook.Session.GetDefaultFolder(olFolderContacts)
xContacts.Display
Set xExplorer = Application.ActiveExplorer
With xExplorer
    .WindowState = olNormalWindow
    .Top = 0
    .Left = xWidth * 2
    .Height = xHeight
    .Width = xWidth
End With
Set xTasks = Outlook.Session.GetDefaultFolder(olFolderTasks)
xTasks.Display
Set xExplorer = Application.ActiveExplorer
With xExplorer
    .WindowState = olNormalWindow
    .Top = 0
    .Left = xWidth * 3
    .Height = xHeight
    .Width = xWidth
End With
End Sub
doc open multiple windows startup 1

3. 接著繼續點擊 插入 > 模組,將以下代碼複製並粘貼到打開的空白模組中,參見截圖:

Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" (ByVal xIndex As Long) As Long
doc open multiple windows startup 2

4. 然後保存並關閉代碼,重新啟動 Outlook 以使代碼生效。現在,當打開 Outlook 時,郵件、日曆、聯絡人和任務窗口將會自動並排打開,參見截圖:

doc open multiple windows startup 3