Skip to main content

 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.

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

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

🤖 AI Mail Assistant: Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 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 ProBatch 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.

Read More       Free Download      Purchase
 

 

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