Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

 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


Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
 
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.