title: Extracting .xlsx attachments from .msg files
body: <p>I know that this has been asked here several times, and I have tried what has apparently worked for others...I have more than 1000 Outlook .msg files with .xlsx file attachments stored in folders on my desktop and I only need to extract the .xlsx files to combine into a single dataframe.</p>
  
  <p>I have tried the <a href="https://stackoverflow.com/questions/48201007/extracting-attachments-from-msg-files-stored-in-many-subfolders-within-main-sh?noredirect=1&amp;lq=1">VBA macro</a>, and Python [Win32] (<a href="https://stackoverflow.com/questions/26322255/parsing-outlook-msg-files-with-python">Parsing outlook .msg files with python</a>) and <a href="https://github.com/mattgwwalker/msg-extractor" rel="nofollow noreferrer">msg-extractor</a>. The best I can do is to extract a single attachment from a single .msg file</p>
  
  <p>Any advice is greatly appreciated. Thank you!</p>
  
  <pre><code>import argparse
  import csv
  import os as os
  import pathlib
  import sys
  from datetime import date, datetime, timedelta, tzinfo
  from enum import Enum, IntEnum
  from tempfile import mkstemp
  
  import dateutil.parser as duparser
  from dateutil.rrule import rrulestr, rruleset
  import pywintypes
  import pytz
  import win32com.client  
  
  path = r'C:\Users\Me\Desktop\MyFiles\feb_2018'
  files = [f for f in os.listdir(path) if '.msg' in f]
  print (files)
  for file in files:
      outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
      msg = outlook.OpenSharedItem(os.path.join(path, file))
      att=msg.Attachments
      for i in att:
          i.SaveAsFile(os.path.join(path, i.FileName))       
  
  
  </code></pre>