Skip to main content
Author: Xiaoyang Last Modified: 2025-05-13

在 Outlook 中,我們可能很容易從電子郵件創建新任務。但是,您是否嘗試過在收到特定郵件時自動創建新任務呢?例如,我只想從老闆的郵件中自動創建任務。您該如何在 Outlook 中處理這個工作呢?

使用 VBA 程式碼在 Outlook 中接收指定郵件時自動創建新任務


使用 VBA 程式碼在 Outlook 中接收指定郵件時自動創建新任務

這項工作沒有直接的方法或規則可以解決,但在此,我可以將 VBA 程式碼和規則結合起來完成它。請按照以下步驟操作:

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

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

VBA 程式碼:在接收郵件時自動創建新任務:

Sub CreateNewTask(Item As Outlook.MailItem)
Dim xNewTask As TaskItem
On Error Resume Next
Set xNewTask = Outlook.CreateItem(olTaskItem)
With xNewTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .DueDate = Item.ReceivedTime + 1
    .Body = Item.Body
    .Importance = olImportanceHigh
    .Save
End With
Set xNewTask = Nothing
End Sub
the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 1

3. 然後保存並關閉程式碼。插入程式碼後,您需要創建一個規則。請點擊「Home」選項卡下的「Rules」>「Manage Rules & Alerts」。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 2

4. 在「Rules and Alerts」對話框中,點擊「New Rule」。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 3

5. 在彈出的「Rules Wizard」中,從「Start from a blank rule」部分選擇「Apply rule on messages I receive」。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 4

6. 點擊「Next」按鈕。在「Step 1: Select condition(s)」列表框中,選擇您要創建的條件。在本例中,我將勾選「from people or public group」選項。然後在「Step 2: Edit the rule description (click an underlined value)」部分,點擊「people or public group」鏈接以打開「Rule Address」對話框,並雙擊您想自動創建任務的郵件地址。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 5

7. 點擊「OK」,然後繼續點擊「Next」。在「Step 1: Select action(s)」列表框中,勾選「run a script」。然後在「Step 2: Edit the rule description (click an underlined value)」部分,點擊「a script」鏈接。將彈出「Select Script」對話框;選擇先前添加的宏並點擊「OK」。

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 6

8. 然後點擊「Next」>「Next」進入「Finish」規則設置屏幕。在「Step 1: Specify a name for this rule」文本框中輸入規則名稱,然後在「Step 2: Setup rule options」部分勾選「Turn on this rule」。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 7

9. 然後點擊「Finish」按鈕和「OK」以關閉「Rules and Alerts」對話框。

10. 從現在開始,一旦您收到來自特定地址的郵件,Outlook 將自動創建相應的任務。您可以在您的任務文件夾中檢查這些任務。請參見截圖:

the screenshot of step about auto creating new tasks when receiving specified emails in Outlook 8