Im new to VBA so I have trouble creating a correct code. I hope to make VBA macro wich would search for latest mail with specific subject and than would open it. The mail is maybe in inbox but it could also be in one of the inbox folders or subfolders. I've managed to create code with pickfolder option and it works but I would like to avoid pickfolder all together. Many thanks for any help given..
Here is my code so far:
Private Sub CommandButton9_Click() Dim OutMail As Object Dim objFolder As Object Dim objNSpace As Object Dim Filter As String Dim Item As Object Filter = ("[ReceivedTime] >= '" & DateValue(Now) & "' AND [ReceivedTime] < '" & DateValue(Now + 1) & "'") Application.ScreenUpdating = False Set objOutlook = CreateObject("Outlook.Application") Set objNSpace = objOutlook.GetNamespace("MAPI") Set objFolder = objNSpace.pickfolder If objFolder Is Nothing Then gblStopProcessing = True MsgBox "Proccess stopped", vbOKOnly, "Warning " Exit Sub End If Set OutMail = objFolder.Items.Restrict(Filter) For Each OutMail In objFolder.Items.Restrict(Filter) If InStr(OutMail.Subject, "Name of the mail") <> 0 Then OutMail.Display End If Next HandleExit: End Sub