LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Can you have a command line arg with a workbook?

Patrick,

Thanks, but I guess I would still need the multiple IF statements (or Select
Case if that works in VBScript?) to cover the different counts?

Also on another note, this script starts a new instance of Excel. Is it
possible to use the existing instance if one already exists?

--
Trefor


"Patrick Molloy" wrote:

use .Arguments.Count to check that you have enough

eg
dim expected
expected = 3
if wscript.arguments.count = expected then
msgbox "OK"
else
msgbox "Missing arg"
end if

"Trefor" wrote in message
...
Patrick / Steve,

This is my first venture into VBScript and I know this is the start of
what
will work for me. As it stands the VBScript will error if all the args are
not specified. What is the best way to handle this?

I tied this and it appears to work, but look a little excessive:

If Arg1 < "" and Arg2 < "" then
objXL.run "TestMacro", CStr(Arg1), CStr(Arg2)
Elseif Arg2 < "" then
objXL.run "TestMacro", CStr(Arg1), ""
Else
objXL.run "TestMacro", "" , ""
End If

--
Trefor


"Steve Yandl" wrote:

Trefor,

I've always used a vbScript file as a sort of helper file to do this sort
of
thing.

For my test, I created a workbook named "C:\Test\TestBk1.xls". In module
1
I created a subroutine named "TestMacro" that takes two text string
arguments.

Now I create a text file that I name "C:\Test\LaunchSub.vbs". The
contents
of this script is shown between the lines below,
________________________________________
arg1 = WScript.Arguments(0)
arg2 = WScript.Arguments(1)


Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set objWkbk = objXL.Workbooks.Open("C:\Test\TestBk1.xls")
objXL.run "TestMacro", CStr(arg1), CStr(arg2)
__________________________________________

Now, the command line that I can use at the prompt for cmd.exe or at the
'Start Run' line for Windows would be:
WScript.exe "C:\Test\LaunchSub.vbs" "dog" "cat"
Note, that I am using WScript.exe with the name of my vbs file as the
first
argument. After that is a space followed by my first argument to go to
the
vbs script and then a second space followed by my final argument. Those
arguments will be retrieved in the WScript.Arguments collection. In the
script, all the arguments will be treated as variant type so you will
want
to convert them to the appropriate data type before sending them to your
Excel macro.


Steve Yandl




"Trefor" wrote in message
...
If it possible to read an arg from the command line in VBA?

myworkbook.xls arg1 arg2

I would like to run a certain macro if a certain argument or parameter
is
specified.
--
Trefor





 
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
Run Macro from Command line Phil Smith Excel Discussion (Misc queries) 1 July 21st 07 06:35 PM
Print an excel file from command line or "cron" type command ??? Chris Salcedo Excel Programming 2 March 28th 07 01:10 AM
VBA & Command Line Soze Excel Programming 1 May 1st 06 06:57 AM
Q: command line in OE JIM.H. Excel Discussion (Misc queries) 0 May 30th 05 10:48 PM
DOS Command Line Chris Excel Programming 5 October 2nd 03 02:06 PM


All times are GMT +1. The time now is 02:26 AM.

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

About Us

"It's about Microsoft Excel"