Question:
How to use Shell with argument in VBA?
Oden91
2008-06-08 06:04:45 UTC
Hi

I am new to VB6 programming.

I am stuck with Shell command. I want to run a EXE with command line arguments i.e.

Shell ("c:\myapplication.exe argument1 argument2")

but it does not work.

what is the right command?
Four answers:
five v
2008-06-09 12:57:17 UTC
The shell function will actually return a number. You'll need to add a variable to collect the returned number:



Dim Ret as Long



Ret = Shell ("c:\myapplication.exe argument1 argument2")



-------------------------------------------

Also, ShellExecute and ShellExecuteEx are available in VBA, but you have to declare the functions first. See below:





Const SW_SHOW = 1

Const SW_SHOWMAXIMIZED = 3



Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _

(ByVal hwnd As Long, _

ByVal lpOperation As String, _

ByVal lpFile As String, _

ByVal lpParameters As String, _

ByVal lpDirectory As String, _

ByVal nShowCmd As Long) As Long



Sub RunYourProgram()

Dim Ret As Long



RetVal = ShellExecute(0, "open", _

"", "", _

"", SW_SHOWMAXIMIZED)



End Sub





There are some useful information and tools for API functions here:

http://allapi.mentalis.org/agnet/apiguide.shtml
?
2016-11-12 12:06:41 UTC
Vba Shell Command
miket
2008-06-08 09:09:26 UTC
That's the correct command and format. However, quoting may be an issue. If there's a space in the path of the exe you have to quote it; e.g.

Shell("""c:\program files\whatever.exe"""+ " arg1 arg2")

or

Shell("""c:\program files\whatever.exe"" arg1 arg2")



BTW you can get way more control over your shelling using ShellExecute or ShellExecuteEx. Much more hassle however. Look those up in msdn help.
?
2016-10-16 06:45:19 UTC
a super type of the denominations accessible began while one individual grasped one mandatory reality approximately or from scripture. This individual began coaching others and tried to assist human beings to verify what they observed. This individual might quickly get carry of a following of persons, needed or no longer. at last this individual died or replaced into killed. the group of followers quickly prepared and based on the only reality the unique individual discovered, they geared up an entire doctrine around. we've a denomination, for sturdy or worse.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...