Skip to main content

如何在Outlook中建立新任務時將預設開始日期設定為今天?

Author: Xiaoyang Last Modified: 2025-05-13

當我們在Outlook中建立新任務時,「開始日期」欄位預設會顯示為「無」,如下方截圖所示。但是,有時候您需要經常將今天的日期設定為開始日期,因此每次都需要手動選擇「開始日期」欄位中的日期。是否有快速的方法可以在Outlook中建立新任務時自動將預設的開始日期設定為今天呢?

the screenshot of step about using vba to set the default start date as today when creating new task in Outlook 1

使用VBA程式碼在Outlook中建立新任務時將預設開始日期設定為今天


使用VBA程式碼在Outlook中建立新任務時將預設開始日期設定為今天

也許沒有其他更好的方法可以直接在Outlook中處理這個問題,這裡我將介紹一種VBA程式碼來解決它。請按照以下步驟操作:

1. 啟動Outlook,然後按住ALT + F11鍵以打開Microsoft Visual Basic for Applications視窗。

2. 在Microsoft Visual Basic for Applications視窗中,雙擊Project1(VbaProject.OTM)面板中的ThisOutlookSession以打開模組,然後將以下程式碼複製並貼上到空白模組中。

VBA程式碼:將預設開始日期設定為今天:

Public WithEvents xInspectors As Outlook.Inspectors
Public WithEvents xTaskItem As Outlook.TaskItem
Private Sub Application_Startup()
   Set xInspectors = Outlook.Inspectors
End Sub
Private Sub xInspectors_NewInspector(ByVal Inspector As Inspector)
    If Not (TypeOf Inspector.CurrentItem Is TaskItem) Then Exit Sub
    Set xTaskItem = Inspector.CurrentItem
End Sub
Private Sub xTaskItem_Open(Cancel As Boolean)
If (Len(xTaskItem.Subject) = 0 And Len(xTaskItem.Body) = 0) And (xTaskItem.StartDate = #1/1/4501# And xTaskItem.DueDate = #1/1/4501#) Then
    xTaskItem.StartDate = Now
End If
End Sub
the screenshot of step about using vba to set the default start date as today when creating new task in Outlook 2

3. 插入程式碼後,將游標放在第二段程式碼處,然後按下 F5鍵執行此程式碼,請參閱截圖:

the screenshot of step about using vba to set the default start date as today when creating new task in Outlook 3

4. 從此以後,每當您建立新任務時,Outlook都會自動將開始日期和結束日期預設設定為當前日期,如下方截圖所示:

the screenshot of step about using vba to set the default start date as today when creating new task in Outlook 4