I'm trying to go through all unread emails in my inbox, find ones that contain a certain subject line, mark them as unread and move to a folder.
It works for some emails but not all unread emails so I end up having to click the button I created for the macro multiple times and i'm not sure why.
Here is the macro:
Sub MoveAlerts()
On Error Resume Next
Set oOutlook = CreateObject("Outlook.Application")
Set oNamespace = oOutlook.GetNamespace("MAPI")
Set oFolderSrc = oNamespace.GetDefaultFolder(olFolderInbox)
Set oFolderDst = oFolderSrc.Folders("@Alerts")
Set oFilteredItems = oFolderSrc.Items.Restrict("[UnRead] = True")
Dim strSubject As String
For Each oMessage In oFilteredItems
If InStr(oMessage.Subject, "high temperature") Or InStr(oMessage.Subject, "Temperature: High") Then
oMessage.UnRead = False
oMessage.Move oFolderDst
End If
Next
End Sub