我正在嘗試從特定檔案夾中獲取今天收到的目標電子郵件。我目前的 VBA 代碼是:
Sub ExportOutlookTableToExcel()
Dim oLookInspector As Inspector
Dim oLookMailitem As MailItem
Dim oLookWordDoc As Word.Document
Dim oLookWordTbl As Word.Table
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWrkSheet As Excel.Worksheet
Dim Today As String
Today = Date
'Grab Email Item
Set oLookMailitem =Application.ActiveExplorer.CurrentFolder.Items("Apples Sales")
Set oLookInspector = oLookMailitem.GetInspector
Set oLookWordDoc = oLookInspector.WordEditor
但是,我的電子郵件位于名為“Apples”的特定檔案夾中,如果我將其移動到收件箱檔案夾,則它可以與 CurrentFolder 方法一起使用。有什么方法可以指定 VBA 應該在哪個檔案夾中抓取電子郵件?
uj5u.com熱心網友回復:
假設檔案夾是收件箱檔案夾上的子檔案夾,請嘗試
set folder = Application.Session.GetDefaultFolder(olFolderInbox).Folders("Folder Name")
如果它與收件箱在同一級別,請使用
set folder = Application.Session.GetDEfaultFolder(olFolderInbox).Parent.Folders("Folder Name")
uj5u.com熱心網友回復:
您可以使用顯示對話框的NameSpace.PickFolder方法Pick Folder。該Pick Folder對話框是一個模態對話框,這意味著在用戶選擇檔案夾或取消對話框之前,代碼不會繼續執行。該方法回傳一個Folder物件,該物件表示用戶在對話框中選擇的檔案夾,或者Nothing該對話框是否被用戶取消。
因此,每次運行 VBA 宏時,您都可以在運行時選擇正確的檔案夾。否則,您必須指定硬編碼的檔案夾名稱。
該NameSpace.GetDefaultFolder方法回傳一個Folder代表該請求的型別為當前輪廓的默認檔案夾物件; 例如,獲取or當前登錄用戶的默認“收件箱日歷”檔案夾。
然后您可以使用Folder.Folders屬性,該屬性回傳Folders代表指定.csv檔案中包含的所有檔案夾的集合Folder。因此,您可能會找到一個子檔案夾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/392489.html
上一篇:觸發復選框點擊事件
