Re: Can you have a command line arg with a workbook?



Patrick,

Great thankyou. Are you able to help with my last question re multiple
instances?

--
Trefor


"Patrick Molloy" wrote:

yes - IF or Select both work - thats down to you to decide what is most
effective

select case wscript.arguments.count
case 0:msgbox "no arguments"
case 1:msgbox "1 arguments"
case 2:msgbox "2 arguments"
case 3:msgbox "3 arguments"
case else :msgbox "more than 3 arguments"



end select

"Trefor" <Trefor@xxxxxxxx> wrote in message
news:8F379FA4-6782-4E9B-818A-82D18FCC10AD@xxxxxxxxxxxxxxxx
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" <Trefor@xxxxxxxx> wrote in message
news:CCBE89FF-1C54-4740-9602-62ADD5F05D7C@xxxxxxxxxxxxxxxx
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" <Trefor@xxxxxxxx> wrote in message
news:A7FC1773-7EAA-4840-B0CB-B13279E0B86F@xxxxxxxxxxxxxxxx
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




.



Relevant Pages

  • Re: Ping Steve Yandl or other VBScript gurus
    ... post on the vbscript newsgroup and that got me going in the right direction. ... 'Run macro named createResumeFromFile, which has no arguments, and catch its ... 'Exit the script with the value of the return code from the macro/function. ... how to do what I want to do entirely in VBA or VBScript; ...
    (microsoft.public.word.vba.general)
  • Re: LDAP query information
    ... execution of the vbscript? ... The error message indicates the line number in the script, ... Dim strBase, strFilter, strAttributes, strQuery, adoRecordset ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)
  • Re: Thank you Richard, Paul and urkec
    ... only built-in way to communicate with the person running the script is ... It is documented in the VBScript help file Script56.chm. ... You can use the ADO and ADOX objects to analyze and manipulate an existing ... dir cmd of each folder to a text file and have my script use that file ...
    (microsoft.public.scripting.vbscript)
  • Re: Ping Steve Yandl or other VBScript gurus
    ... Steve Yandl suggested using VBScript when I asked ... I'm trying to add one small wrinkle to the script and can't figure ... The macro that I am launching from the VBScript is ... be that 'dim bWaitOnReturn' didn't define the variable as Boolean but ...
    (microsoft.public.word.vba.general)
  • Re: Thank you Richard, Paul and urkec
    ... It is documented in the VBScript help file Script56.chm. ... You can use the ADO and ADOX objects to analyze and manipulate an existing ... object browser to help those who script its VBA (like a VBScript but also ... I'm trying to create a script that will read the folder properties of the ...
    (microsoft.public.scripting.vbscript)