我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)
这是运行时错误:
运行时错误'-2147287038(80030002)':
无法打开文件:AUTO Andy Low Yong Cheng不在办公室(2014年9月22日返回).msg.
该文件可能不存在,您可能没有权限打开它,或者它可能在另一个程序中打开.右键单击包含该文件的文件夹,然后单击"属性"以检查该文件夹的权限.
您好我想从位于磁盘上的现有创建Outlook.MailItem(我相信).我将路径存储在一个字符串中,并希望访问以保存它的正文和附件.
我似乎无法弄清楚如何在c#中打开它并访问它.
目前我有一些东西
其中fl评估为"C:\ users\msgs\email.msg"之类的内容
谢谢你的时间
Outlook.Application app = new Outlook.Application();
try
{
foreach (String fl in Directory.GetFiles(docInfo.LocalPath + _preprocessorDirectory))
{
if (Regex.IsMatch(fl.Trim(), _regex, RegexOptions.IgnoreCase))
{
Outlook.MailItem email = new Outlook.MailItem(fl);
SaveAttachments(email);
SaveBody(email);
}
}
}
catch (Exception ex)
{
logger.Error("Error in Process for document " + docInfo.OriginalPath, ex);
callback.Invoke(docInfo, false);
}
return false;
Run Code Online (Sandbox Code Playgroud)