How to open an Outlook.msg file from my hard drive, which is NOT in Outlook?

I searched high and low for this seemingly simple task, but all the links that I encounter are either stored on the hard drive or read from the Outlook folder.

I have the following code that iterates over the file names in a folder on my hard drive, but I don’t know how to take this path and open it using Outlook.

Dim inPath as String Dim thisFile as String Dim msg as MailItem Dim OlApp as Object Set OlApp = CreateObject("Outlook.Application") inPath = "C:\temp" thisFile = Dir(inPath & "\*.msg") Do While thisFile <> "" 'At this point, thisFile contains the path of a .msg like "C:\temp\mail_item1.msg" 'msg = <open mailitem> <~~~~ HELP HERE 'Do stuff with msg thisFile = Dir Loop 

This question was similar, but was for C #, so I was having problems getting the vba equivalent associated with my problem. Maybe this will be obvious to someone more familiar with Outlook vba.

+5
source share
1 answer

See here http://msdn.microsoft.com/en-us/library/office/ff865637.aspx

 Sub CreateFromTemplate() Dim MyItem As Outlook.MailItem Set MyItem = Application.CreateItemFromTemplate("C:\statusrep.oft") MyItem.Display End Sub 

Not just for .oft files

 Set MyItem = Application.CreateItemFromTemplate("C:\temp\mail_item1.msg") 

Edit - I forget about OpenSharedItem all the time. http://msdn.microsoft.com/en-us/library/office/bb208171(v=office.12).aspx

+6
source

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


All Articles