I Have below vba code which works with vba "For Each Loop". The problem is that I have used the below code in some other program, but in that the condition is same just I want to remove the loop thing in it.
The code should execute and stop after completing the task once. In short I want to remove the loop and do it in such a way where code runs without loop.
Set olNs = outlookApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items
For Each olMail In myTasks
If (InStr(1, olMail.Subject, ws.Range("E" & FinalRow), vbTextCompare) > 0) Then
olMail.Display
End If
Next olMail
Exit Forjust beforeNext olMailif you want torun it just once. If you want to exit after theifcondition is met place it beforeEnd if.