跳到主要內容

 如何在Outlook中的郵件或任務中查找和替換主題文本?

在Outlook中,如果有多個郵件主題或任務主題需要用您指定的文本替換,您當然可以一個個地更改它們,但是,您是否有任何快速的方法可以在Outlook中一次完成此工作?

使用VBA代碼在多封郵件中查找和替換主題文本

使用VBA代碼在多個任務中查找和替換主題文本


使用VBA代碼在多封郵件中查找和替換主題文本

查找特定的文本並在多個消息主題中替換為另一個,下面的VBA代碼可以幫您一個忙,請執行以下步驟:

1。 選擇您要查找的電子郵件並替換主題文本,然後按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 然後,點擊 插入 > 模塊,將以下代碼複製並粘貼到打開的空白模塊中,請參見屏幕截圖:

VBA代碼:在多個消息中查找並替換主題文本:

Option Explicit
Sub FindAndReplaceInSubject()
Dim xItem As Object
Dim xNewSubject As String
Dim xMailItem As MailItem
Dim xExplorer As Explorer
Dim i As Integer
On Error Resume Next
Set xExplorer = Outlook.Application.ActiveExplorer
For i = xExplorer.Selection.Count To 1 Step -1
    Set xItem = xExplorer.Selection.Item(i)
    If xItem.Class = olMail Then
        Set xMailItem = xItem
        With xMailItem
            xNewSubject = Replace(.Subject, "kte", "Kutools for Excel")
            .Subject = xNewSubject
            .Save
        End With
    End If
Next
End Sub

備註:在上面的代碼中: xNewSubject = Replace(.Subject,“ kte”,“ Kutools for Excel”)觀塘線延線”是您要查找的舊文本,“Excel的Kutools”是您要替換的新文本。 請根據需要更改它們。

doc替換主題1

3。 然後按 F5 鍵以運行此代碼,並且消息主題中的特定文本已根據需要用新文本替換,請參見屏幕截圖:

doc替換主題2


使用VBA代碼在多個任務中查找和替換主題文本

如果您需要在任務中查找和替換主題文本,以下VBA代碼也可以為您提供幫助。

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

2。 然後,點擊 插入 > 模塊,將以下代碼複製並粘貼到打開的空白模塊中,請參見屏幕截圖:

VBA代碼:在所有任務中查找並替換主題文本:

Option Explicit
Sub FindReplaceTextsInAllTaskSubjects()
Dim xPane As NavigationPane
Dim xModule As TasksModule
Dim xGroup As NavigationGroup
Dim xNavFolder As NavigationFolder
Dim xTaskItem As Outlook.TaskItem
Dim i, k As Integer
Dim xFindStr, xReplaceStr As String
Dim xTotalCount As Long
On Error Resume Next
xFindStr = InputBox("Type the words to find:", "Kutools for Outlook", xFindStr)
If Len(Trim(xFindStr)) = 0 Then Exit Sub
xReplaceStr = InputBox("Type the words to replace:", "Kutools for Outlook", xReplaceStr)
If Len(Trim(xReplaceStr)) = 0 Then Exit Sub
xTotalCount = 0
Set xPane = Outlook.Application.ActiveExplorer.NavigationPane
Set xModule = xPane.Modules.GetNavigationModule(olModuleTasks)
Set xGroup = xModule.NavigationGroups.Item(1)
For i = xGroup.NavigationFolders.Count To 1 Step -1
    Set xNavFolder = xGroup.NavigationFolders.Item(i)
    For k = xNavFolder.Folder.Items.Count To 1 Step -1
        Set xTaskItem = xNavFolder.Folder.Items(k)
        If InStr(xTaskItem.Subject, xFindStr) > 0 Then
            xTaskItem.Subject = Replace(xTaskItem.Subject, xFindStr, xReplaceStr)
            xTaskItem.Save
            xTotalCount = xTotalCount + 1
        End If
    Next
Next
MsgBox xTotalCount & " task subjects have been changed!", vbInformation + vbOKOnly, "Kutools for Outlook"
End Sub

3。 然後按 F5 鍵執行此代碼,並彈出一個提示框,請輸入您要從任務主題中找到的文本,請參見屏幕截圖:

doc替換主題3

4。 點擊 OK,然後彈出另一個提示框,請輸入您要替換為的新文本,請參見屏幕截圖:

doc替換主題4

5. 然後點擊 OK,並顯示一個對話框,告訴您已更改了多少個主題,請參見屏幕截圖:

doc替換主題5

6。 點擊 OK,並且任務主題中的舊文本已被新文本替換,請參見屏幕截圖:

doc替換主題6


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

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

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hallo,
beide Funktionen sind echt super.
Bin aber auch auf der Suche nach einer Lösung wo ich den Betreff mehrerer Mails ändern kann, genau wie hier bei den Aufgaben.

Ich möchte den Text in den Betreffzeilen kürzen und verwende hierzu z.B. bei München nur ein M
Mails also markieren, suche München im Betreff und ändere München in "M".
Kann mir jemand helfen?
This comment was minimized by the moderator on the site
Hello, Bördi
To find and replace the text of subject in emails, you just need to apply the first VBA code of this article.
Please select the emails first, and then apply the below code:
Option Explicit
Sub FindAndReplaceInSubject()
Dim xItem As Object
Dim xNewSubject As String
Dim xMailItem As MailItem
Dim xExplorer As Explorer
Dim i As Integer
On Error Resume Next
Set xExplorer = Outlook.Application.ActiveExplorer
For i = xExplorer.Selection.Count To 1 Step -1
    Set xItem = xExplorer.Selection.Item(i)
    If xItem.Class = olMail Then
        Set xMailItem = xItem
        With xMailItem
            xNewSubject = Replace(.Subject, "Munich", "M")
            .Subject = xNewSubject
            .Save
        End With
    End If
Next
End Sub


Please try, hope it can help you!
This comment was minimized by the moderator on the site
Is there a way to change the subject line of email(s) in a folder (window level) via vba?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations