简体   繁体   English

处理 zip 附件 Outlook vba 脚本

[英]Process zip attachments outlook vba script

I need to create a macro in outlook to redirect some emails to a specific folder.我需要在 Outlook 中创建一个宏来将一些电子邮件重定向到特定文件夹。

I have to discriminate plus 10 MB attachments but with the condition thant the files included in the zip should be processed and if the uncompressed content are greater than 10 MB these should also be taking into account.我必须区分 10 MB 的附件,但条件是 zip 中包含的文件应该被处理,如果未压缩的内容大于 10 MB,这些也应该考虑在内。

I would like to know how to unzip the files check the size of all of them, if the total size of the files are greater than 10MB send to one folder, otherwise send it another folder.我想知道如何解压缩文件检查所有文件的大小,如果文件总大小大于 10MB 发送到一个文件夹,否则发送到另一个文件夹。

The Attachment class provides the Size property which returns a Long indicating the size (in bytes) of the attachment. Attachment 类提供了Size属性,该属性返回一个 Long,指示附件的大小(以字节为单位)。

To get the uncompressed size you need to save the attached file on the disk and then extract the content.要获得未压缩的大小,您需要将附件保存在磁盘上,然后提取内容。 The SaveAsFile method of the Attachment class saves the attachment to the specified path. 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

See Unzip file(s) with the default Windows zip program (VBA) for the code to unzip files.有关解压缩文件的代码,请参阅使用默认 Windows zip 程序 (VBA)解压缩文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM