title: Using VBA in outlook to automatically download Zip floders onto computer
body: <p>I want to use VBA in Outlook to download a series of zip files. I have coded up to the point where it successfully go through all the emails in my subfolder and download whatever attachment is inside. It tested it on an excel attachment and it worked well.</p>
  <p>However the files that I am trying to download are Zip files.</p>
  <p>When I run the script on emails containing Zips I get this weird looking file.</p>
  <h3>screen shot of weird looking result</h3>
  <p><img src="https://i.stack.imgur.com/4KHAg.jpg" alt="screen shot of weird looking result" /></p>
  <p>below is my code.
  Please help!</p>
  <pre><code>Sub GetAttachments()
      'declaring an error statement
      On Error GoTo GetAttachments_err
          
      'Declaring my variables
      'NameSpace: Obj tha gives you access to all outlooks folders
      Dim ns As NameSpace
      'This will refer to a mail folder
      Dim Inbox As MAPIFolder
      Dim Item As Object
      'Attachment we are looking for
      Dim Atmt As Attachment
      'Used to create a name and save path for each attachment as it is saved.
      Dim FileName As String
      'Counter to log the progress of the macro
      Dim i As Integer
      'to look in the subfliter i am filtering all the exception reports to
      Dim SubFolder As MAPIFolder
      
      'setting the variables
      Set ns = GetNamespace(&quot;MAPI&quot;)
      Set Inbox = ns.GetDefaultFolder(olFolderInbox)
      Set SubFolder = Inbox.Folders(&quot;Post-Algo: Mapping Exception Reports&quot;)
      i = 0
      
      'if statment to check if there are any messages in the inbox folder and abandon search if there are none.
      If SubFolder.Items.Count = 0 Then
          MsgBox &quot;There are no messages in the Inbox.&quot;, vbInformation, _
             &quot;Nothing Found&quot;
          Exit Sub
      End If
      
      'starts looking for attachments if there are items in the file
      If SubFolder.Items.Count &gt; 0 Then
          'looks at each item in the inbox
          For Each Item In SubFolder.Items
              'looks at each attachment
              For Each Atmt In Item.Attachments
                  'creates a file name by appending the fiel name
                  'remember to change the path to the desired location and to creat the file path.
                  FileName = &quot;H:\exceptionDownload\&quot; &amp; Item.Subject &amp; &quot; &quot; &amp; i &amp; Atmt.FileName
                  'saves the file under that name.
                  Atmt.SaveAsFile FileName
                  'increment the log variable.
                  i = i + 1
              Next Atmt
          Next Item
      End If
      
      
      If i &gt; 0 Then
          MsgBox &quot;I found &quot; &amp; i &amp; &quot; attached files.&quot; _
             &amp; vbCrLf &amp; &quot;I have saved them into the H:\exceptionDownload\.&quot; _
             &amp; vbCrLf &amp; vbCrLf &amp; &quot;Have a nice day.&quot;, vbInformation, &quot;Finished!&quot;
      Else
          MsgBox &quot;I didn't find any attached files in your mail.&quot;, vbInformation, _
          &quot;Finished!&quot;
      End If
      
  ' Clear the values of the variables
  GetAttachments_exit:
     Set Atmt = Nothing
     Set Item = Nothing
     Set ns = Nothing
     Exit Sub
  
  'error handling
  GetAttachments_err:
     MsgBox &quot;An unexpected error has occurred.&quot; _
        &amp; vbCrLf &amp; &quot;Please note and report the following information.&quot; _
        &amp; vbCrLf &amp; &quot;Macro Name: GetAttachments&quot; _
        &amp; vbCrLf &amp; &quot;Error Number: &quot; &amp; Err.Number _
        &amp; vbCrLf &amp; &quot;Error Description: &quot; &amp; Err.Description _
        , vbCritical, &quot;Error!&quot;
     Resume GetAttachments_exit
  
  
  
  End Sub
  </code></pre>