【发布时间】:2015-09-03 16:53:47
【问题描述】:
我正在尝试使用 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。
该文件可能不存在,您可能没有打开它的权限,或者它可能在另一个程序中打开。右键单击包含该文件的文件夹,然后单击属性以检查您对该文件夹的权限。
【问题讨论】:
-
刚刚重新编辑并发布了运行时错误thx
-
在继续之前,您是否实际调试过代码以查看
thisFile的值是多少? -
如何调试这个文件你能教我吗
-
点击代码左侧的灰色竖条,它会高亮显示执行将进入调试模式的那一行。然后将鼠标放在您希望看到的变量上! ;)