kalekje / LNCHR-pub

MIT License
23 stars 4 forks source link

Outlook search: how to I change default to Archive and not All Folders? #1

Closed Avastgard closed 1 year ago

kalekje commented 1 year ago

Try looking through this documentation: https://learn.microsoft.com/en-us/office/vba/api/outlook.olsearchscope

At a quick glance, Archive isn't an option and it might be a bit trickier.

Avastgard commented 1 year ago

Thanks, I'll try to work something out.

Avastgard commented 1 year ago

In case anyone is facing the same problem as I was, here's the workaround solution I came up with:

OutlookSearch(searchstr)
{
      Send "^#{Left}"          ; goes to the first virtual desktop, where I always have my outlook window. Still don't know how to find a window across several virtual desktops
    Sleep 100
    WinActivate("ahk_class rctrl_renwnd32")          ; Activate the Outlook window
    Sleep 500
    Send "^{y}"          ; Opens the "Go to Folder" window in Outlook.
    Sleep 50
    Send "arch"          ; Types "arch", so Archive is selected in the list
    Send "{Enter}"          ; Effectively opens the Archive folder so the rest of the actions can be performed there
    Sleep 500
    searchstr := StrReplace(searchstr, "!", " hasattachments:yes")
    olApp := GetOutlookCom()
    static olSearchScopeCurrentFolder := 0          ; Changed the scope so it only looks at the current folder (Archive)
    olApp.ActiveExplorer.Search(searchstr, olSearchScopeCurrentFolder)
    ControlSend "{Tab}", "RICHEDIT60W1", "ahk_class rctrl_renwnd32"          ; Send Tab to hide the "suggested searches" drop down
    return
}