Skip to main content

How to find and replace subject text within messages or tasks in Outlook?

Author Xiaoyang Last modified

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

Notes: 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.

doc replace subjects 1

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:

doc replace subjects 2

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:

doc replace subjects 3

4. Click "OK", and another prompt box is popped out, please enter the new text that you want to replace with, see screenshot:

doc replace subjects 4

5. Then click "OK", and a dialog box is displayed to tell you how many subjects have been changed, see screenshot:

doc replace subjects 5

6. Click "OK", and the old texts in the task subjects has been replaced with the new ones, see screenshot:

doc replace subjects 6

Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook with 100+ incredible features! Click to download now!

πŸ€– Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.

πŸ“§ Email Automation: Auto Reply (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: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

πŸ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

πŸ‘ One-click Wonders: Reply All with 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 ...

Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Instantly unlock Kutools for Outlook with a single click. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2