1
我試圖將所有電子郵件解壓到外部程序(AIMMS)。我首先將它全部存儲在Excel中以供閱讀。讀取CC和BCC屬性時出錯
我寫了一些VBA代碼。當該字段中有多個電子郵件地址時,。至函數不起作用(導致即時錯誤)。 .CC和.BCC也是如此。
Sub Extract_mail(MailBoxName As String, Pst_Folder_Name As String, Subfolder As String)
'Add Tools->References->"Microsoft Outlook nn.n Object Library"
Dim folders As Outlook.folders
Dim Folder As Outlook.MAPIFolder
Dim iRow As Integer
Dim objMItem As MailItem
If Subfolder = "" Then
Set Folder = Outlook.Session.folders(MailBoxName).folders(Pst_Folder_Name)
Else
Set Folder = Outlook.Session.folders(MailBoxName).folders(Pst_Folder_Name).folders(Subfolder)
End If
If Folder = "" Then
MsgBox "Invalid Data in Input"
GoTo end_lbl1:
End If
'Rad Through each Mail and export the details to Excel for Email Archival
ActiveWorkbook.Sheets("Sheet1").Cells.Clear
ActiveWorkbook.Sheets("Sheet1").Cells(1, 1) = "ID"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 2) = "To"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 3) = "EmailAddress"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 4) = "Name"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 5) = "Subject"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 6) = "Date"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 7) = "Body"
ActiveWorkbook.Sheets("Sheet1").Cells(1, 8) = "Size"
For iRow = 1 To Folder.Items.Count
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 1).Select
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 1) = iRow
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 2) = Folder.Items.Item(iRow).To
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 3) = Folder.Items.Item(iRow).SenderEmailAddress
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 4) = Folder.Items.Item(iRow).SenderName
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 5) = Folder.Items.Item(iRow).Subject
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 6) = Folder.Items.Item(iRow).ReceivedTime
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 7) = Folder.Items.Item(iRow).Body
ActiveWorkbook.Sheets("Sheet1").Cells(iRow + 1, 8) = Folder.Items.Item(iRow).Size
Next iRow
ActiveWorkbook.Save
'ActiveWorkbook.Close
end_lbl1:
End Sub
太好了!這是真的:)謝謝,也清理代碼!快速的問題:運行後,我無法打開它來查看數據,一切都是灰色的,我不能通過在Excel中的標籤。我該如何解決這個問題? –
這是一個很好的問題,不幸的是我沒有答案。我寫的代碼不應該導致這種行爲。如果你對答案滿意,你能接受它作爲答案嗎?謝謝。 – CoRrRan