Outlook 2013, Outlook 2016 VBA rearrange folders in folders tree - vba

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).

Related

outlook search options

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.

Copy one account client-side rule to all client-side rules

Is there any way to copy the outlook rule of one account to another account using VBA code. I have researched on the internet I have not found anything related to my question, Pls help me. I will be very thankful to you.
The Outlook object model doesn't provide any property or method for that. However, you can use a low-level functionality to access rules. Use the PropertyAccessor object to get and set item-level properties that are not explicitly exposed in the Outlook object model, or properties for the following non-item objects: AddressEntry, AddressList, Attachment, ExchangeDistributionList, ExchangeUser, Folder, Recipient, and Store.
Rules are kept as hidden items in your Inbox folder (see the associated content which is not visible in the Outlook UI). You may use MFCMAPI or OutlookSpy for exploring the hidden content.

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.

Persisting VBA/VBScript macro settings

I've created an Outlook (2010) VBScript macro that has some user-configurable settings. I've googled and checked the likely resources and can't figure out a good way to persist them. I'm currently storing them in the body of a mail item! It don't get much kludgier than that!
Should I use the Windows registry? An ini file? Or??? And whether registry, file, or???, what key/folder/??? would I use?
Just before hitting 'Post' on this I tried one more google search and hit on this: http://www.jkp-ads.com/articles/DistributeMacro08.asp.
The gist I took away was, ini file or registry are both kosher. One nice thing about VBA's use of the registry is it automatically puts "app" data in the approved place, just need to give your "app" a key. Since my data is just a big string with parsing code already in place, I used strData = GetSetting(strAppKey, strSection, strLeafKey) and SaveSetting(strAppKey, strSection, strLeafKey, strData) and voila, all is good.
The standard Outlook way of storing settings, especially if they relate to a particular mailbox/store and can be accessed from multiple machines connected to the same mailbox, is to use a hidden message stored in one of the well known folders, such as the Inbox.
The hidden MAPI messages can be accessed using MAPIFolder.GetStorage: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.mapifolder.getstorage.aspx

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.