简体   繁体   中英

Process zip attachments outlook vba script

I need to create a macro in outlook to redirect some emails to a specific folder.

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.

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.

The Attachment class provides the Size property which returns a Long indicating the size (in bytes) of the attachment.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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