Hello All,
I'm sure this topic has been asked before, but I was receiving the below error message when using this forums search function.
header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 17200'); // in seconds print "TEST123";
I would like to create a macro that, when executed, would search my current inbox for any emails with the keyword in either the body or subject (from sender would also be great), and move them to the specified folder. Below is the code which somewhat works. There are a few issues that need to be resolved.
- The macro must be executed each time in order to move a single email from the inbox to the destination folder. The goal is to have this macro move all items that fit the specified criteria be moved in a single keystroke (click).
- The macro does not move items with the keyword in the subject, only emails with the keyword in the body will get moved to the destination folder.
If there is a better method for moving folders than using an InStr, I would be happy to use that as well. This code is far from optimal as my limited experience with VBA is from excel, not outlook. The below code has been copied from different sources to fit my needs.
Thank you for your time
Sub MoveWidget()
Dim outlookApp
Dim olNs As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Dim myDestFolder As Outlook.Folder
Dim olMail As Variant
Dim myTasks As Object
Set outlookApp = CreateObject("Outlook.Application")
Set olNs = outlookApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myDestFolder = Fldr.Folders("Widget")
Set myTasks = Fldr.Items
For Each olMail In myTasks
If (InStr(1, olMail.Body, "Widget", vbTextCompare) > 0) Then
olMail.Move myDestFolder
ElseIf (InStr(1, olMail.Subject, "Widget", vbTextCompare) > 0) Then
olMail.Move myDestFolder
ElseIf (InStr(1, olMail.SenderEmailAddress, "Widget", vbTextCompare) > 0) Then
olMail.Move myDestFolder
End If
Exit For
Next
End Sub
Bookmarks