我可以使用VBA或C#來完成此任務。如何以編程方式將郵件項目從目錄文件夾移動到MS Outlook?
問題:存儲在目錄文件夾中(例如:C:\temp
)中有100多個郵件項目(.msg
,包含主題行的未發送電子郵件,收件人行和附件)。
如何遍歷郵件並將它們發送到MS Outlook 2010中的文件夾?
我嘗試在VBA中使用FileSystemObject
,我可以遍歷目錄中的「文件」。但是,我無法將文件投到MailItem
以將每個文件移到MS Outlook。
我嘗試:
Public Sub Move_MailItems_To_Outlook_From_Directory_Folder()
Dim directoryPath As String
Dim directoryFolder As Object
Dim aFile As File
Dim fso As New FileSystemObject
Dim outlookApp As Outlook.NameSpace
Dim emailFolder As Outlook.Folder
directoryPath = "\\Client\F$\temp\"
Set directoryFolder = fso.GetFolder(directoryPath)
Set outlookApp = Application.GetNamespace("MAPI")
' Iterate thru files and add to MS Outlook "Drafts" folder.
For Each aFile In directoryFolder.Files
' !!!! "ERROR: One or more parameter values are not valid." !!!
'
' I don't think VBA provides a means to cast a File object as a MailItem
' object, which is what I imagine the Items.Add method expects as a parameter
' value.
outlookApp.GetDefaultFolder(olFolderDrafts).Items.Add aFile
Next
End Sub
這是否需要通過編程完成 - 你能代替只是將文件從那裏」的文件夾拖放到Outlook重新儲存? –
感謝您的建議。在這種情況下,拖放+拖放不實用。郵件項目被創建並存儲在網絡驅動器中,因此將驅動器中的文件拖放到MS Outlook草稿文件夾時性能很差。第二次從文件夾拖放到「草稿」文件夾時,一次僅限於7個郵件項目。因此,在代碼中這樣做是我理想的解決方案,因爲每次執行此任務時,都可以節省員工拖放數分鐘的時間。我會測試你的Cimperiali解決方案! Tim,完美, –