使用 Excel 中的 VBA 打开 Outlook 邮件 .msg 文件

2023-11-26

我试图使用 VBA 从指定目录打开 .msg 文件但我不断收到运行时错误。

我的代码:

Sub bla()
    Dim objOL As Object
    Dim Msg As Object
    Set objOL = CreateObject("Outlook.Application")
    inPath = "C:\Users\SiliconPlus\Desktop\Si+ Contact Lists\Contact_Si+"
    thisFile = Dir(inPath & "\*.msg")
    Set Msg = objOL.CreateItemFromTemplate(thisFile)
    ' now use msg to get at the email parts
    MsgBox Msg.Subject
    Set objOL = Nothing
    Set Msg = Nothing
End Sub

这是运行时错误:

运行时错误'-2147287038 (80030002)':

无法打开文件:AUTO Andy Low Yong Cheng 不在办公室(返回 22 09 2014).msg。

该文件可能不存在,您可能没有打开它的权限,或者它可能已在其他程序中打开。右键单击包含该文件的文件夹,然后单击属性以检查您对该文件夹的权限。


Kenneth Li You 打开文件时没有完整路径。尝试这个:

Sub bla_OK()
Dim objOL As Object
Dim Msg As Object
Set objOL = CreateObject("Outlook.Application")
inPath = "C:\Users\SiliconPlus\Desktop\Si+ Contact Lists\Contact_Si+"
thisFile = Dir(inPath & "\*.msg")
'Set Msg = objOL.CreateItemFromTemplate(thisFile)
Set Msg = objOL.Session.OpenSharedItem(inPath & "\" & thisFile)
' now use msg to get at the email parts
MsgBox Msg.Subject
Set objOL = Nothing
Set Msg = Nothing
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Excel 中的 VBA 打开 Outlook 邮件 .msg 文件 的相关文章

随机推荐