title: VB Script to open all Excel Files in a folder and run macros present in them
body: <p>I'm trying to get to a VB Script that opens every Excel file in a given folder, runs the macro written in them (the macro is written as <code>Workbook_Open()</code> so it executes automatically) and the closes the files.</p>
  
  <p>Currently, I have this code I have pasted below, but it does not work. It simply shows the messages that it has completed opening on macros, but does nothing to the workbooks.</p>
  
  <pre><code>OpenAllFiles()
  MsgBox "Completed opening all Excel files in the folder."
  
  Sub OpenAllFiles()
  
      dim fso
      dim thisfolder
      dim allfiles
  
      Set WshShell = WScript.CreateObject("WScript.Shell")
      set fso= Wscript.CreateObject("Scripting.FileSystemObject")
      set thisfolder = fso.GetFolder("C:\Users\ad6975\Desktop\Project\02 2014 IC\04 IC4\02 Goal Reporting\Test")
      set allfiles = thisfolder.Files
  
      Dim XL
      Set XL = CreateObject("excel.application") 
  
      For each onefile in allfiles
          if (onefile.type = "Microsoft Office Excel 97-2003 Worksheet" Or onefile.type = "Microsoft Excel Worksheet") then
  
              Dim XLWkbk
              Set XLWkbk = XL.Workbooks.Open(onefile)
              XL.DisplayAlerts = False
              Call XLWkbk.SaveAs(onefile.Path, 56, , , , , ,2)
              XLWkbk.Close
              Set XLWkbk = Nothing
  
          end if
      Next
  
      XL.Quit
      Set XL = Nothing 
  
  End Sub
  </code></pre>