Consulting

Results 1 to 3 of 3

Thread: Excel VBA search other email account than default

  1. #1
    VBAX Newbie
    Joined
    Dec 2021
    Posts
    2
    Location

    Excel VBA search other email account than default

    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

    vba excel.doc
    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
    Last edited by Aussiebear; 12-20-2021 at 08:12 PM. Reason: Attached supplied code

  2. #2
    VBAX Newbie
    Joined
    Dec 2021
    Posts
    2
    Location
    Solved. Thanks.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Interesting..... Just how did you solve this issue?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •