我有大約90。味精,我需要打開Outlook文件,轉換成Excel附件爲.csv文件,並保存了。目前,下面的代碼是簡單地打開.msg展望文件,但出現錯誤:無法打開.msg文件
如何允許打開.msg文件。
腳本:
Sub OpenMSGRenameDownloadAttachement()
Dim objOL As Outlook.Application
Dim Msg As Outlook.MailItem
Dim MsgCount As Integer
Set objOL = CreateObject("Outlook.Application")
'Change the path given month, ie. do this for Jan, Feb, April
inPath = "C:\January Messages"
thisFile = LCase(Dir(inPath & "\*.msg"))
Do While thisFile <> ""
Set Msg = objOL.Session.OpenSharedItem(thisFile)
Msg.Display
MsgBox Msg.Subject
thisFile = Dir
Loop
Set objOL = Nothing
Set Msg = Nothing
End Sub
我想這是一個明顯的問題,但該文件已經打開?例如。在Outlook中?或者在Excel中,您的代碼在早期嘗試失敗?或從以前的成功嘗試在Excel中? (它看起來並不像您明確正在執行「Close」,因此它可能仍然是開放的。)此外,此頁面是否適用:https://support.microsoft.com/zh-cn/help/2633737/the -openshareditem-method-for-outlook-holds-a-file-handle-on-signed-.msg-files – YowE3K
這是一次性的事情。我如何重寫這個工作,至少打開郵件,我可以從那裏轉換excel。 – Sauron
您正在使用Dir錯誤。嘗試使用'thisFile = Dir(inPath)'並在'Do While thisFile <>「」'後放置一個If條件'如果Right(thisFile,3)=「msg」Then'',並且不需要物理地打開消息據我所知,獲得附件。 – Tehscript