Hello, I am trying to adapt this code for using the macro only in unread emails in my Inbox, but I don’t get anything that works. Someone for helping me? THanks in advance.
Public Sub Unread_eMails()
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myDestFolder = myInbox.Folders("CHECK")
'For Each MyItem In myInbox
For Each MyItem In Application.ActiveExplorer.¿?¿?¿? 'I don't know what type here... I tried of this way too but don't work For Each MyiTem in myInbox
If myInbox.UnReadItemCount <> 0 Then
If InStr(MyItem.Body, "alarm") > 0 Then
MyItem.Move myDestFolder
Else
If InStr(MyItem.Subject, "Urgent") > 0 Then
MyItem.Move myDestFolder
Else
If InStr(MyItem.Body, "Closed") > 0 Then
MyItem.Categories = "Closed"
MyItem.Save
End If
End If
End If
MyItem.UnRead = False
End If
Next MyItem
End Sub
Public Sub Unread_eMails()
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myDestFolder = myInbox.Folders("CHECK")
'For Each MyItem In myInbox
For Each MyItem In Application.ActiveExplorer.¿?¿?¿? 'I don't know what type here... I tried of this way too but don't work For Each MyiTem in myInbox
If myInbox.UnReadItemCount <> 0 Then
If InStr(MyItem.Body, "alarm") > 0 Then
MyItem.Move myDestFolder
Else
If InStr(MyItem.Subject, "Urgent") > 0 Then
MyItem.Move myDestFolder
Else
If InStr(MyItem.Body, "Closed") > 0 Then
MyItem.Categories = "Closed"
MyItem.Save
End If
End If
End If
MyItem.UnRead = False
End If
Next MyItem
End Sub