View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Denis[_4_] Denis[_4_] is offline
external usenet poster
 
Posts: 38
Default How to pass parameters to excel from wscript (Windows script)

On Tuesday, November 5, 2013 4:12:56 PM UTC-6, Denis wrote:
I have a windows script (wscript.exe) that I use to call excel from a batch script. Now I have an excel application where I need to pass in an excel parameter using this wscript. I understand parameters can be passed in via the /e tag (eg, /e/parm1/parm2/...) but I don't know how I can do this from the wscript. Unfortunately, I haven't been able to find anything by googling or searching this group. Anybody know how to do this?



Here's my wscript:



Dim xlApp



Set xlApp = CreateObject("Excel.application")



Set xlWb = xlApp.workbooks.Open("c:\somedir\...\some.xls")



xlApp.Quit



Set xlWb = Nothing

Set xlApp = Nothing



Denis


I think I have found the solution to my problem. I create a helper macro in my .xls and then call this helper macro from my script with my parameter(s). This looks like this:

Set xlWb = xlApp.workbooks.Open("c:\somedir\...\some.xls")
xlApp.run "HelperMacro", "SomeParameterValue"

This HelperMacro does what needs to be done with whatever parameter(s) is passed to it.

This isn't an ideal solution for my application since this .xls (which I inherited) is set to automatically run when the above workbooks.Open above is executed. But I know a way to work around that.

If there is a way to pass in a parameter(s) directly when the workbooks.Open is executed I would still be interested in such a solution but I can live with this Helper Macro approach.

Denis