title: VBSscript to run Excel macro not working
body: <p>I have been trying to put together a VBSscript that will run an Excell macro. I have used several scripts from other threads on this forum as well as scripts found elsewhere on the web.</p>
  
  <p>I found this forum to be the most helpful to others with similiar questions. The experts here are just that: experts.</p>
  
  <p>I am new to script writing. My experience is limited to cutting and pasting example scripts in a trial and error process. With this particular script I just can't seem to find the correct combination to run an excell macro from a VBSscript.</p>
  
  <p>Here is the code I am currently running:</p>
  
  <pre><code>Set xlObj = CreateObject("Excel.application")
  xlObj.Workbooks.Open "C:\Documents and settings\user\Desktop\Excel_macro_email.xls"
  xlObj.Run "macro_email" 'name of macro
  xlObj.ActiveWorkbook.Saved = True
  xlObj.ActiveWindow.Close
  xlObj.Quit
  </code></pre>
  
  <p>I'm using XLnow OnScript Editor to compile/debug the script and the editor sees no problems. When I double click on the .vbs file the cmd window pops up for just a second and I can see that there is some output there but can't read it as it closes so fast. (I've also researched how to output the results to a file but I'm getting way, way over may head with all this.</p>
  
  <p>Is anyone willing to help correct this script? If you can help, and suggest some code, please also include where to place the code in the script, or perhaps you might include it in a complete script. What to do with the suggestions I find here is almost as much of a problem as what code to use.</p>
  
  <p>Thank you for any help you can offer. I apologize for my lack of expertise. In the end, with a little help, I will learn by the experience. </p>
  
  <p>This is an update of the script with the sub added as suggested below:</p>
  
  <pre><code>Sub OpenAndRun (Excel_macro_email)
  
  Set xlObj = CreateObject("Excel.Application")
  xlObj.Workbooks.Open "C:\Documents and Settings\user\Desktop\Excel_macro_email.xls"
  xlObj.Run "Excel_macro_email.xls,macro_email"
  xlObj.ActiveWorkbook.Saved = True
  xlObj.ActiveWindow.Close
  xlObj.Quit
  
  End Sub
  </code></pre>
  
  <p>I'm still not getting the macro to run. The cmd windows briefly opens as before but now I do not see any output when it flashes bye.</p>
  
  <p>Any suggestions?</p>
  
  <p><em><strong>This is to post the solution to this problem'</em></strong></p>
  
  <p>Thanks for your response.</p>
  
  <p>I have tried seceral versions of this script. In the latest version I added a "Sub" line and "End Sub" which probably helped. The final solution was when I discovered that the file extension for the Excel file was not .xls but .xlsm. When I added that "m" (for macro enabled, I guess) the latest version of script started working.</p>
  
  <p>Her is the working version:</p>
  
  <pre><code>Option Explicit
  
  Dim xlApp, xlBook
  
  Set xlApp = CreateObject("Excel.Application")
  '~~&gt; Change Path here
  Set xlBook = xlApp.Workbooks.Open("C:\Users\Thomas\Desktop\Excel_macro_email.xlsm", 0, True)
  xlApp.Run "macro_email"
  xlBook.Close
  xlApp.Quit
  
  Set xlBook = Nothing
  Set xlApp = Nothing
  
  WScript.Echo "Finished."
  WScript.Quit
  </code></pre>
  
  <p>I hope this helps anyone else with the same problem. Thanks for you help.</p>