2015-05-15 2 views
0

Мне нужно создать макрос в Outlook, чтобы перенаправить некоторые письма в определенную папку.Процесс zip вложения outlook vba script

Я должен различать вложения плюс 10 МБ, но при условии, что файлы, включенные в zip, должны быть обработаны, и если несжатый контент превышает 10 МБ, это также следует учитывать.

Я хотел бы знать, как распаковать файлы, проверить размер всех из них, если общий размер файлов превышает 10 МБ, отправляется в одну папку, в противном случае отправляйте другую папку.

+0

1. Каков ваш вопрос; 2. Что вы пробовали? –

ответ

0

Класс Attachment предоставляет свойство Size, которое возвращает Long, указывающее размер (в байтах) вложения.

Чтобы получить несжатый размер, вам необходимо сохранить прикрепленный файл на диске и извлечь его. Метод SaveAsFile класса Attachment сохраняет вложение в указанный путь.

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) для кода для распаковки файлов.

Смежные вопросы