[英]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.