Open an Outlook Outlook item using EntryID, StoreID, and / or PR_ENTRYID

NOTE. I use VBA and Office 2007. (I would use C #, but the project options do not allow this)

I'm trying to find some method in Outlook or the API that will allow me to open an Outlook mail item by providing either the Outlook EntryID property or the MAPI property "PR_ENTRYID" from the Access database. I found a lot of links to the specified code, but I never saw anyone really post a solution. I tried to include links to mapi32.dll and OLMAPI32.dll, but I get the following error: "Unable to add a link to the specified file." I assume this is because these dlls are for .NET.

Any help you can give would be greatly appreciated.

+6
source share
2 answers

Use Namespace.GetItemFromID . Please note that the second parameter (store identifier) ​​is optional. You can omit it if the store in question has already been affected by Outlook in the current session. If not, Outlook will raise the "unknown id id" exception. If an identifier for the entry in the store is specified, Outlook will open it first, and the store provider will have the opportunity to register their login identifiers in the MAPI system.

 set App = CreateObject("Outlook.Application") set NS = App.GetNamespace("MAPI") NS.Logon set Msg = NS.GetItemFromID(EntryID) MsgBox Msg.Subject 
+16
source

For C #:

 var ns = OutlookApp.GetNamespace("MAPI"); var item = ns.GetItemFromID(entryId) as MailItem; 

If OutlookApp is of type Microsoft.Office.Interop.Outlook._Application.

+2
source

Source: https://habr.com/ru/post/897430/


All Articles