Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing SQLPlus script location using Windows Script Host Object Model Scott Spence Excel Programming 11 February 2nd 12 01:41 PM
How do I pass parameters into Excel from a URL? David Jankowski Excel Programming 0 April 4th 06 09:52 PM
Is there a way to pass parameters to a web query in excel daytonsupply Excel Programming 1 February 23rd 05 04:10 PM
Starting Excel from cmd pmpt, pass parameters Jerry G. Slater Excel Programming 2 February 5th 04 05:38 AM


All times are GMT +1. The time now is 12:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"