[英]Process zip attachments outlook vba script
我需要在 Outlook 中創建一個宏來將一些電子郵件重定向到特定文件夾。
我必須區分 10 MB 的附件,但條件是 zip 中包含的文件應該被處理,如果未壓縮的內容大於 10 MB,這些也應該考慮在內。
我想知道如何解壓縮文件檢查所有文件的大小,如果文件總大小大於 10MB 發送到一個文件夾,否則發送到另一個文件夾。
Attachment 類提供了Size屬性,該屬性返回一個 Long,指示附件的大小(以字節為單位)。
要獲得未壓縮的大小,您需要將附件保存在磁盤上,然后提取內容。 Attachment 類的SaveAsFile方法將附件保存到指定路徑。
Sub SaveAttachment()
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myInspector = Application.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to save the first attachment in the current item to the Documents folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
myAttachments.Item(1).SaveAsFile Environ("HOMEPATH") & "\My Documents\" & _
myAttachments.Item(1).DisplayName
End If
Else
MsgBox "The item is of the wrong type."
End If
End If
End Sub
有關解壓縮文件的代碼,請參閱使用默認 Windows zip 程序 (VBA)解壓縮文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.