Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass parameters to excel from wscript (Windows script)
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass parameters to excel from wscript (Windows script)
Denis wrote:
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. check that http://www.vbforums.com/showthread.p...90#post2234990 The idea is to read command line parameters using that Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long but read entire post to see how these parameters must be prepared as command line arguments. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass parameters to excel from wscript (Windows script)
On Thursday, November 7, 2013 12:00:53 AM UTC-6, witek wrote:
Denis wrote: 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. check that http://www.vbforums.com/showthread.p...90#post2234990 The idea is to read command line parameters using that Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long but read entire post to see how these parameters must be prepared as command line arguments. Yes, I saw how you can use this GetCommandLine to retrieve command line parameters and you can set command line parameters using the /e tag. However, I haven't found anything that shows whether you can set these command line parameters when a .xls is invoked from a visual basic script (eg, workbooks.Open(...xls). Probably that's because there really isn't a "command line" in this case. If there were a way to do this, then this command line approach would be preferable to a helper macro. Denis |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass parameters to excel from wscript (Windows script)
I'm inclined to go with something like this in that workbook' _Open
event... Application.Run "HelperMacro", "SomeParameterValue" ...so your process runs when the workbook opens. -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass parameters to excel from wscript (Windows script)
OR more simply...
Call HelperMacro(SomeParameterValue) ...where both my suggestione assume the procedure is stored in the xls. Otherwise, you need to ref the external source workbook! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Passing SQLPlus script location using Windows Script Host Object Model | Excel Programming | |||
How do I pass parameters into Excel from a URL? | Excel Programming | |||
Is there a way to pass parameters to a web query in excel | Excel Programming | |||
Starting Excel from cmd pmpt, pass parameters | Excel Programming |