How do I open an outlook .msg file from my harddrive that is NOT in outlook?

非 Y 不嫁゛ 提交于 2019-11-26 21:51:18

问题


I have searched high and low for this seemingly simple task, but all references I come across are either saving to the hard-drive or reading from an outlook folder.

I have the following code that loops through file names in a folder on my hard-drive, but I do not know how to take that path and open it with 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 looked similar but was for C#, so I had some trouble getting the vba equivalent related to my problem. Maybe it will be obvious to someone more familiar with outlook vba.


回答1:


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 keep forgetting about OpenSharedItem. http://msdn.microsoft.com/en-us/library/office/bb208171(v=office.12).aspx



来源:https://stackoverflow.com/questions/19383290/how-do-i-open-an-outlook-msg-file-from-my-harddrive-that-is-not-in-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!