处理 zip 附件 outlook vba 脚本

Process zip attachments outlook vba script

我需要在 outlook 中创建一个宏来将一些电子邮件重定向到特定文件夹。

我必须区分加上 10 MB 的附件,但前提是应该处理 zip 中包含的文件,如果未压缩的内容大于 10 MB,也应该考虑这些。

我想知道如何解压缩文件检查所有文件的大小,如果文件的总大小大于 10MB 则发送到一个文件夹,否则发送到另一个文件夹。

附件 class 提供 Size 属性 其中 returns 一个 Long 表示附件的大小(以字节为单位)。

要获得未压缩的大小,您需要将附件保存在磁盘上,然后提取内容。 Attachment class 的 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)