Skip to main content

如何在Outlook日曆中搜索和替換約會主題?

Author: Siluvia Last Modified: 2025-08-06

當你需要將某些主題替換為相同文字時,或者在Outlook數據導入後需要替換主題字段中的“Copy”一詞時,使用Outlook日曆中的查找和替換功能非常有用。本文提供了一段VBA代碼來幫助你搜索和替換多個約會主題。請瀏覽更多詳細信息。

使用VBA代碼搜索和替換約會主題


使用VBA代碼搜索和替換約會主題

在本節中,你可以按照以下步驟使用VBA代碼搜索和替換約會主題。

1. 首先,你需要在Outlook中將宏設置調整為低安全性。

1) 在Outlook 2010和2013中,點擊「文件」>「選項」。在「Outlook選項」對話框中,點擊左側的「信任中心」,然後點擊「信任中心設置」按鈕。

doc-find-and-replace-subject-1

在「信任中心」對話框中,點擊左側的「宏設置」,然後在「宏設置」部分選擇「啟用所有宏」選項,並點擊「確定」按鈕。參見截圖:

doc-find-and-replace-subject-2

2) 在Outlook 2007中,請點擊「工具」>「信任中心」。在「信任中心」對話框中,點擊左側的「宏設置」,然後選擇「不檢查宏的安全性」選項,並點擊「確定」按鈕。

doc-find-and-replace-subject-3

2. 按下「Alt」+「F11」鍵打開「Microsoft Visual Basic for Applications」窗口。

3. 在「Microsoft Visual Basic for Applications」窗口中,雙擊展開「project1」>「Microsoft Outlook Objects」>「ThisOutlookSession」以打開VBA編輯器。參見截圖:

doc-find-and-replace-subject-4

4. 複製並將以下VBA代碼粘貼到VBA編輯器中。然後按下「F5」鍵運行代碼。

VBA:查找和替換約會主題

Sub FindReplaceAppointment()
    Dim oApp As Outlook.Application
    Dim oCalFolder As Outlook.MAPIFolder
    Dim oAppt As Outlook.AppointmentItem
    Dim sOldText As String
    Dim sNewText As String
    Dim iCalChangedCount As Integer
    Set oApp = Outlook.Application
    MsgBox ("This script will perform a find/replace in the subject line of all appointments in a specified calendar.")
    sOldText = InputBox("What is the text string that you would like to replace?")
    sNewText = InputBox("With what would you like to replace it?")
    ' Check to be sure a Calendar folder was selected
    Do
    If Not (oCalFolder Is Nothing) Then
        If (oCalFolder.DefaultItemType = olAppointmentItem) Then Exit Do
    End If
    MsgBox ("Please select a calendar folder from the following list.")
    Set oCalFolder = Application.Session.PickFolder
    On Error GoTo ErrHandler:
    Loop Until oCalFolder.DefaultItemType = olAppointmentItem
    ' Loop through appointments in calendar, change text where necessary, keep count
    iCalChangedCount = 0
    For Each oAppt In oCalFolder.Items
        If InStr(oAppt.Subject, sOldText) <> 0 Then
            Debug.Print "Changed: " & oAppt.Subject & " - " & oAppt.Start
            oAppt.Subject = Replace(oAppt.Subject, sOldText, sNewText)
            oAppt.Save
            iCalChangedCount = iCalChangedCount + 1
        End If
    Next
    ' Display results and clear table
    MsgBox (iCalChangedCount & " appointments had text in their subjects changed from '" & sOldText & "' to '" & sNewText & "'.")
    Set oAppt = Nothing
    Set oCalFolder = Nothing
Exit Sub
ErrHandler:
    MsgBox ("Macro terminated.")
End Sub

5. 運行代碼後,會彈出一個「Microsoft Outlook」對話框。點擊「確定」按鈕。

doc-find-and-replace-subject-5

6. 在第二個「Microsoft Outlook」對話框中,輸入你想替換的文字,然後點擊「確定」按鈕。

doc-find-and-replace-subject-6

7. 在第三個「Microsoft Outlook」對話框中,輸入你想用作替換的文字,然後點擊「確定」。

doc-find-and-replace-subject-7

便簽:如果你只想從指定日曆的主題中刪除所有“Copy”單詞,請將此框留空。

8. 點擊下方對話框中的「確定」按鈕。

doc-find-and-replace-subject-8

9. 在「選擇文件夾」對話框中,選擇指定郵件帳戶下的日曆,然後點擊「確定」按鈕。參見截圖:

doc-find-and-replace-subject-9

10. 然後會彈出一個對話框通知你替換成功。請點擊「確定」按鈕。

doc-find-and-replace-subject-10

11. 接下來,所選日曆中所有主題的文字都已替換為新內容。


最佳 Office 生產力工具

最新消息:Kutools for Outlook 推出免費版本!

體驗全新 Kutools for Outlook,擁有100+ 強大功能!立即下載!

🤖 Kutools AI 運用先進 AI 技術,輕鬆處理郵件,包括答覆、摘要、優化、擴寫、翻譯與撰寫郵件。

📧 郵件自動化自動回覆(支援 POP 和 IMAP) / 計劃發送郵件 / 發送郵件時根據規則自動抄送密送 / 自動轉發(高級規則) / 自動新增問候語 / 自動將多收件人郵件分割為個別郵件 ...

📨 郵件管理撤回郵件 /依主題等條件阻擋詐騙郵件 / 刪除重複郵件 / 高級搜索 / 整合文件夾 ...

📁 附件專業版批次保存 / 批次拆離 / 批次壓縮 / 自動保存 / 自動拆離 / 自動壓縮 ...

🌟 介面魔法😊更多精美酷炫表情符號 /重要郵件來臨提醒 / 最小化 Outlook 而非關閉 ...

👍 一鍵神技帶附件全部答復 /反釣魚郵件 / 🕘顯示發件人時區 ...

👩🏼‍🤝‍👩🏻 聯絡人與日曆批次從選中郵件新增聯絡人 / 將聯絡人組分割為多個組 / 移除生日提醒 ...

以您偏好的語言使用 Kutools —— 支援英語、西班牙語、德語、法語、中文及40 多種其他語言!

只需一鍵即可立即啟用 Kutools for Outlook。立即下載,提升您的效率!

kutools for outlook features1 kutools for outlook features2