ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to pass parameters to excel from wscript (Windows script) (https://www.excelbanter.com/excel-programming/449454-how-pass-parameters-excel-wscript-windows-script.html)

Denis[_4_]

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

Denis[_4_]

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

witek

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.


Denis[_4_]

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

GS[_2_]

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


GS[_2_]

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



All times are GMT +1. The time now is 06:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com