Have been wrestling with the following sub-routine.
I use it personally for my computer, the problem is that in my colleagues' computers it doesn't work because he decided to separate his inbox in different folders (this is supposed to loop through all the emails in the default folder).
I modified it a bit using code I've found here but it doesn't seem to work. Can you guys help me find where I went wrong?
Sub LoopReply3(Filepath As String, name As String)
Dim objNS As Outlook.Namespace: Set objNS = Outlook.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder
Dim item As Object
Dim Newmail As MailItem
Dim mailfolder As Outlook.Items
Dim sFilter As String
sFilter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0037001f"" like '%" & name & "%'"
For Each olFolder In objNS.Folders
Set mailfolder = olFolder.Items.Restrict(sFilter)
mailfolder.Sort "ReceivedTime", True
For Each item In mailfolder
If TypeOf item Is Outlook.MailItem Then
Dim oMail As Outlook.MailItem: Set oMail = item
'The problem is not the code that is supposed to go here
End If
End If
Next
Next
End Sub