Here is a VBA code to search inbox in Outlook by any Email ID of a person.
If you like you can also create a button on ribbon in outlook and assign this code.
Sub SearchByEmailID()Dim olApp As Outlook.ApplicationDim ns As Outlook.namespaceDim sSearchMail As StringDim oSearchFolder As Outlook.FolderDim sSearchCriteria As StringDim strFilter As StringDim oContact As Outlook.ContactItemDim iFile As IntegerDim sInp As StringSet olApp = New Outlook.ApplicationSet ns = olApp.GetNamespace("MAPI")sSearchMail = "[email protected]" 'Change EmailID here.Set oSearchFolder = ns.GetDefaultFolder(olFolderInbox)Set olApp.ActiveExplorer.CurrentFolder = oSearchFoldersSearchCriteria = "from:" & sSearchMailolApp.ActiveExplorer.Search sSearchCriteria, olSearchScopeAllFoldersSet olApp = NothingEnd Sub
How to Install and Use the Macro:
In order to use the macro, Open Outlook and Press Alt +F11 key. This will open the VBA editor in outlook.
Go to Insert menu and insert a module and paste the above code and Press save button and close the window.
Now Go to Outlook and and Press Alt+F8 key.
You will see a macro named SearchByEmailID. Press the Run button. This will filter the inbox with the Email ID.
If you like this article or have any query/suggestions, please share your feedback in the comments section below..
Thanks,
Ashwani
I am starting a weekend VBA training course from 06 Jan 2024. If you are interested, please register yourself and go through the course details. Here is the link below:
If you want to develop macro for any Microsoft office product
or
automate your task in excel please reach out to my Fiverr account, mentioned below:
0 comments:
Post a Comment