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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can VBA run DOS commands 1

Status
Not open for further replies.

JasonPurdueEE

Technical User
May 21, 2002
131
US
can VBA run DOS commands? I want to automate a process for openening a command line and changing directories and then running the command:

dir/b/s >C:\list.txt

and then dropping the list into an excel file in a column. any ideas? or is this not possible with VBA?
 
Jason,

There might well be other options, but here's one that will work...

Sub BatchFile_SetList_01()
'runs the following batch file

Shell "C:\setlist.bat", vbHide

End Sub

Of course you would then place your
dir/b/s >C:\list.txt
into the batch file.

Hope this is a workable option. :) Please advise as to whether it's suitable.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Sub get_zip_app_list()

Dim x As String
Dim r As Integer

r = 1
x = Dir("C:\zip_app\*.*")
Cells(r, 1) = x
r = r + 1
Do While x$ <> &quot;&quot;
x$ = Dir()
Cells(r, 1) = x
r = r + 1
Loop

End Sub
 
The previous example populates col A in the sheet that it is run from with the files in c:\zip_app


---------------------
oops...you can change
x$ = Dir()
to
x = Dir()

 
thank you. got this one working. should mention that I used a .cmd file instead of .bat because I am in a NT/2K environment. works wonders. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top