outlook search options - vba

I have on outlook access to public folders. On the public folders incoming mails with an attachment pdf form Customers. The current situation is I need to search all 50 folders one by one for keywords in the attachment to find which one is for me. I’m trying to
Find a way to search all folders and subfolders at one’s.
2.find a way to alert me when incoming messages with the keyword as arrived.
Thank you very much
I tried all possible settings and tried VBA macro

Find a way to search all folders and subfolders at one’s.
Use the AdvancedSearch method of the Application class from the Outlook object model. The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
You can stop the search process at any moment using the Stop method of the Search class.
Read more about that method in the article I wrote for the technical blog - Advanced search in Outlook programmatically: C#, VB.NET.
2.find a way to alert me when incoming messages with the keyword as arrived. Thank you very much
You can handle the NewMailEx event of the Application class in Outlook. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Use the Entry ID to call the NameSpace.GetItemFromID method and process the item.

Related

Display all e-mails with certain category in Outlook

I would like to create a macro that will display all e-mails in certain category. So far I am using
Sub GDPR()
Dim myOlApp As New Outlook.Application
txtSearch = "category:=(""Personal Data"")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
Set myOlApp = Nothing
End Sub
it works but a bit strange, because it also shows an e-mails without any category, but including Personal Data in the body.
I thought that the category:= syntax is special for categories only, and by using it only categorized e-mail will be returned.
Any better method to achive that apart using search function macro?
The Search method accepts a search string that can contain any valid keywords supported in Instant Search. It behaves as if the user has typed the query string in the Instant Search user interface and then clicked Search. Do you get the same results on the UI in Outlook?
When calling Search, the query is run in the user interface, and there is no programmatic mechanism to obtain the search results. For more information on Instant Search, query for "Instant Search" in the Outlook Help. Moreover, the Search method does not provide a callback to enable the developer to determine when the search is complete.
I'd suggest using the AdvancedSearch method of the Application class instead. The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
You can stop the search process at any moment using the Stop method of the Search class.
Ability to save results to the search folder, so the results will be visible in the Outlook UI.
You will be notified when the search process is completed.
Read more about the AdvancedSearch method in the Advanced search in Outlook programmatically: C#, VB.NET article.
Also, if you don't need to show results in the UI, you may consider using the Find/FindNext or Restrict methods of the Items class. You can read more about them in the following articles:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder

searching in outlook public folder by using vb.net

Is there a way to search in outlook public folders by using vb.net. I have tried to search all the web and I didn't find.
You are free to use the Restrict or Find/FindNext methods of the Items class. Read more about these methods in the following series of articles:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
Also, you may find the AdvancedSearch method of the Application class helpful. The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
You can stop the search process at any moment using the Stop method of the Search class.
Read more about that method in the Advanced search in Outlook programmatically: C#, VB.NET article.

Outlook 2013, Outlook 2016 VBA rearrange folders in folders tree

In Outlook versions after 2007 Microsoft added the possibility to manually arrange folders in folders tree (in Outlook 2007 folders were arranged alphabetically).
Is there any possibility using VBA to arrange folders in the folders tree, e.g. put folder to the top when it contains new email?
Thanks
Starting from Outlook 2013 you can reorder folders however you like and Outlook would remember the order. The key property is PR_SORT_POSITION. Here’s the definition:
define PR_SORT_POSITION PROP_TAG( PT_BINARY, 0x3020)
Outlook will use this property as part of it’s sort order when requesting folders from a provider, so it’s important that your provider can handle sorting on a binary property – or can fake it when asked to sort by this property. Outlook will also use this property directly when deciding where to insert nodes in the visible tree, so it’s also important that your provider can return this property when Outlook looks for it on a folder.
There’s a second property Outlook will use for custom sort ordering:
define PR_SORT_PARENTID PROP_TAG( PT_BINARY, 0x3021)
As the name suggests, this property stores an entry ID which can be used to sort a folder under a different node than it’s natural parent. Normally, a folder will be sorted under the folder represented by PR_PARENT_ENTRYID. This property allows you to suggest a different parent for display.
By presetting these properties appropriately, you can direct Outlook in how you wish your provider’s folders to be sorted. And if you allow Outlook to write to these properties, you can preserve whatever sort order your users desire.
So, theoretically you can set these properties from VBA. The PropertyAccessor class can help you with such tasks. Also you may consider using a low-level code if you face with any restrictions from OOM, so any wrappers around Extended MAPI allows to bridge the gap (for example, Redemption).

How to search unread mail in Outlook with VBScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am able to open Outlook, focus it to the inbox folder, and count unread mails with .Unread.
I would like to be able to search unread email for a particular email address in the body of the emails.
I am using Windows 7 with Outlook 2007.
You need to use the Restrict or Find/FindNext methods of the Items class. Take a look at the following articles for the sample code and more information about them:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
For example, to find all unread emails in the folder you can use the following search criteria:
[UnRead] = true
Also you may find the AdvancedSearch method of the Application class helpful. The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
Finally, you can stop the search process at any moment using the Stop method of the Search class.
The Outlook object model provides three main ways for working with item bodies:
Body - a string representing the clear-text body of the Outlook item.
HTMLBody - a string representing the HTML body of the specified item.
Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the message body.

Outlook VSTO attach meta data

I am writing an Outlook addin that inserts content into an email, and I have a emailSent event that I would like send an event back to my server letting me know some content was shared.
Is there a way to attach some meta information to the email (or the word doc, which is what you are creating in outlook) so that I can grab that meta info so I can send it back to my server.
Right now, the only way I think I can do it is to search through the email on the send event looking for my content with regex and pull out the info i need, but that seems cumbersome, and also means I need to run the regex for every email sent, even when they haven't added my content.
There is the concept of MAPI user properties, which you can add to an Outlook item. Since Office 2007 the object model allows access to them. If your add-in must run also with older Outlook version, you should recurr to use Redemption (which I prefer also for higher office versions because it has more flexibility, albeit a greater footprint in distribution).
See UserProperties Interface on MSDN.