title: How to run multiple macros in a directory with different files also present in the folder using python?
body: <p>For running a single macro I am using the following code. You have to enter the details of file path and for that I am using an excel sheet that contain all the locations of macro in one workbook. I am converting that excel into a dataframe and then using column values as an input. But every column contain location to one specific directory which can contain single or multiple macros existing with other file types and directories as well.</p>
  <pre><code>def run_excel_macro (file_path, separator_char):
  
      xl = win32.Dispatch('Excel.Application')
      xl.Application.visible = False #change to True if you are desired to make Excel visible
  
      try:
          wb = xl.Workbooks.Open(os.path.abspath(file_path)) #To open the workbook
          xl.Application.run(file_path.split(sep=separator_char)[-1] + &quot;!main.simpleMain&quot;)
          wb.Save()
          wb.Close()
  
      except Exception as ex:
          template = &quot;An exception of type {0} occurred. Arguments:\n{1!r}&quot;
          message = template.format(type(ex).__name__, ex.args)
          print(message)
  
      xl.Application.Quit()
      del xl
  
      file_name = file_path.split('\\')
      print(file_name[-1])
  
  length = len(df)
  for i in range(length):
      file__path = df['Macro File Path'][i]
      separator__char = os.sep
      run_excel_macro(file__path,separator__char)
  </code></pre>