PDA

View Full Version : [SOLVED:] Excel VBA search other email account than default



signet
12-20-2021, 12:17 PM
I have a specific email account I want to search. I dont want to use getdefaultfolder or change my default folder. I just want to search the inbox of my other outlook account. I am devolving into a pile of know nothing goo, please help.

Now I have failed a using copy paste to add the code I am using. I attached it

Thanks

29239

Dim oOutlook As Object
Dim oNS As Object
Dim oItems As Object
Dim oFilterItems As Object
Dim oFilterItem As Object
Dim sFilter As String
Dim bOutlookOpened As Boolean
Dim i As Long
Const olFolderInbox = 6
Dim rest As String
rest = Worksheets("Sheet1").Cells(5, 1).Value
Set oNS = oOutlook.GetNamespace("MAPI")
Set oItems = oNS.GetDefaultFolder(olFolderInbox)
sFilter = "@SQL=""urn:schemas:httpmail:subject"" like '%" + rest + "%'"
Set oFilterItems = oItems.Items.Restrict(sFilter)
oFilterItems.Sort "[SentOn]", True
Debug.Print ""
Debug.Print "The last matching e-mail is:"
For Each oFilterItem In oFilterItems
If oFilterItem.Class = 43 Then
Debug.Print , oFilterItem.Subject, oFilterItem.SentOn, oFilterItem.SenderEmailAddress
Exit For
End If
Next

signet
12-20-2021, 09:57 PM
Solved. Thanks.

Aussiebear
12-22-2021, 12:58 AM
Interesting..... Just how did you solve this issue?