【发布时间】:2015-05-15 14:04:46
【问题描述】:
我需要在 Outlook 中创建一个宏来将一些电子邮件重定向到特定文件夹。
我必须区分加上 10 MB 的附件,但条件是应该处理 zip 中包含的文件,如果未压缩的内容大于 10 MB,这些也应该考虑在内。
我想知道如何解压文件检查所有文件的大小,如果文件总大小大于10MB,则发送到一个文件夹,否则发送另一个文件夹。
【问题讨论】:
-
1.你的问题是什么; 2. 你试过什么?
我需要在 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
请参阅Unzip file(s) with the default Windows zip program (VBA) 了解解压缩文件的代码。
【讨论】: