我需要从目录中打开所有.MSG文件。
此代码有效
Sub GetMSG()
Dim objOL As Outlook.Application
Dim Msg As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
inPath = "C:\Users\Krishna\Desktop\Test\"
MsgBox inPath
thisFile = LCase(Dir(inPath & "\*.msg"))
MsgBox thisFile
Do While thisFile <> ""
Set Msg = objOL.Session.OpenSharedItem(inPath & thisFile)
Msg.Display
thisFile = Dir
Loop
下面的代码失败(我需要使用文件浏览器)
Dim Msg As Outlook.MailItem
Dim oShell As Object
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
Set oShell = CreateObject("Shell.Application").BrowseForFolder(0, "Select Folder with attachments", 0)
If oShell Is Nothing Then MsgBox "Folder was not selected", vbCritical: Exit Sub
FldPth = oShell.self.Path
thisFile = LCase(Dir(FldPth & "\*.msg"))
MsgBox thisFile
Do While thisFile <> ""
Set Msg = olApp.Session.OpenSharedItem(FldPth & thisFile)
Msg.Display
thisFile = Dir
Loop
当我对位置进行硬编码时,我能够打开所有文件。 Shell应用程序出现错误。
答案 0 :(得分:1)
好像Set Msg = olApp.Session.OpenSharedItem(FldPth & thisFile)
中缺少路径分隔符,将其添加并查看其是否有效。