Skip to main content


Showing posts with the label Office 365

Outlook VBA search for string in email body

How to search for a string in the body of Outlook emails?

How to search for a string in Outlook emails using VBA?

How to find a string in Outlook email body using VBA?

Outlook VBA code below searches a string on the email body and move the email to a specified folder.

Replace variables below with the actual folders and string to search in Outlook:

string to be searched

Folder_to_be_Searched - all emails in this folder will be searched and if the string matches the will be moved automatically to the destination folder. 

string to be searched - this string will match on the body of the emails

Sub MailItemContent_Move_Search()
Dim olItem As Outlook.MailItem Dim sText As String Dim myNameSpace As Outlook.NameSpace Dim myInbox As Outlook.MAPIFolder Dim myDestFolder2 As Outlook.MAPIFolder Dim mySearchFolder As Outlook.MAPIFolder
Set myNameSpace = Application.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)