How to find and replace subject text within messages or tasks in Outlook?
In Outlook, if there are multiple message subjects or task subjects need to be replaced with your specified text, of course, you can change them one by one, but, do you have any quick way to finish this job at once in Outlook?
Find and replace subject text within multiple messages by using VBA code
Find and replace subject text within multiple tasks by using VBA code
Find and replace subject text within multiple messages by using VBA code
Find the specific text and replace with another in multiple message subjects, the below VBA code can do you a favor, please do with following steps:
1. Select the emails that you want to find and replace the subject text, and then, hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Then, click Insert > Module, copy and paste below code into the opened blank module, see screenshot:
VBA code: Find and replace the subject text within multiple messages:
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
Note: In the above code: xNewSubject = Replace(.Subject, "kte", "Kutools for Excel"), “kte” is the old text you want to find, and “Kutools for Excel” is the new text that you want to replace with. Please change them to your need.
3. Then press F5 key to run this code, and the specific text in the message subjects have been replaced with the new text as you need, see screenshot:
Find and replace subject text within multiple tasks by using VBA code
If you need to find and replace the subject text in tasks, the following VBA code also can help you.
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Then, click Insert > Module, copy and paste below code into the opened blank module, see screenshot:
VBA code: Find and replace the subject text within all tasks:
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. Then press F5 key to execute this code, and a prompt box is popped out, please type the text that you want to find from the task subjects, see screenshot:
4. Click OK, and another prompt box is popped out, please enter the new text that you want to replace with, see screenshot:
5. Then click OK, and a dialog box is displayed to tell you how many subjects have been changed, see screenshot:
6. Click OK, and the old texts in the task subjects has been replaced with the new ones, see screenshot:
Best Office Productivity Tools
Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook
📧 Email Automation: Out of Office (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
📨 Email Management: Easily Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
📁 Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
🌟 Interface Magic: 😊More Pretty and Cool Emojis / Boost Your Outlook Productivity with Tabbed Views / Minimize Outlook Instead of Closing ...
👍 One-click Wonders: Reply All with Incoming Attachments / Anti-Phishing Emails / 🕘Show Sender's Time Zone ...
👩🏼🤝👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Over 100 Features Await Your Exploration! Click Here to Discover More.