Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone know if you can execute

Status
Not open for further replies.

monsjic

Programmer
Jan 23, 2002
23
US
Does anyone know if you can execute DOS command line statements in VBA? I would like to run 'dir /s >c:\temp.txt' from the command prompt

Thanks in advance for any help
 
In an NT environment, you can execute the following code to perform actions in a command window:

Dim tstcmd as String
tstcmd = "CMD.EXE dir /s > c:\temp.txt"
Call Shell(tstcmd,0)

You can replace the CMD.EXE with the equivalent Windows 98 command interpreter COMMAND.COM
 
I tried this, and it doesnt appear to be working.
My code...

[tt]
Private Function createFL() As Long
Dim strCMD As String
strCMD = "CMD.EXE dir /o:n /s " & _
strSrchPth & "*.db " & _
"> %TEMP%\SRSDBLst.txt"
Call Shell(strCMD, 0)

MsgBox Err.Description, , Err.Number
End Function
[/tt]

...the strSrchPth is a var defined by a browse
for folder dialog. The strCMD string looks like
this when it is executed...
[tt]
"CMD.EXE dir /o:n /s \\Nwea_1\SRS_Services\Customer\*.db > %TEMP%\SRSDBLst.txt"
[/tt]
To test this out, I typed the command (actually
copy & pasted) into a DOS box, and it worked fine
(removed the CMD.EXE of course).

If I go to Start, Run, and enter the above line
(including the CMD.EXE) it just gives me a DOS
box, but doesnt process the arg.

Anyone know why this is?

Tj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top