跳到主要内容

 如何在Outlook中的邮件或任务中查找和替换主题文本?

在Outlook中,如果有多个邮件主题或任务主题需要用您指定的文本替换,您当然可以一个个地更改它们,但是,您是否有任何快速的方法可以在Outlook中一次完成此工作?

使用VBA代码在多封邮件中查找和替换主题文本

使用VBA代码在多个任务中查找和替换主题文本


使用VBA代码在多封邮件中查找和替换主题文本

找到特定的文本并在多个消息主题中替换为另一个,下面的VBA代码可以帮您一个忙,请执行以下步骤:

1。 选择您要查找的电子邮件并替换主题文本,然后按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

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")观塘线延线”是您要查找的旧文本,“Kutools for Excel”是您要替换的新文本。 请根据需要更改它们。

doc替换主题1

3。 然后按 F5 键以运行此代码,并且消息主题中的特定文本已根据需要用新文本替换,请参见屏幕截图:

doc替换主题2


使用VBA代码在多个任务中查找和替换主题文本

如果您需要查找并替换任务中的主题文本,以下VBA代码也可以为您提供帮助。

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

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