DOS Command

J

JF Bouthillier

Hi all,

Can someone tell me if it is possible to run a DOS
command through VBA code? If so, how?

Thank you very much.
JF
 
6

'69 Camaro

You can usually use the Shell( ) function or the ShellExecute( ) Windows API
function for DOS commands, but it depends upon the command and the OS. For
an example that works in all versions of Windows:

Dim RetVal As Double

RetVal = Shell("C:\WINDOWS\CALC.EXE", vbNormalFocus) ' Runs Calculator.

You can find an example of how to use the ShellExecute( ) function on this
Web page:

http://www.mvps.org/access/api/api0018.htm

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Any human can read my reply E-mail address and should alter it so that a
message will be forwarded to me. Spammers are free to use my UNALTERED
reply E-mail address. I will *never* get those messages!)
 
D

Douglas J. Steele

<quibble>
That won't work on my machine at work, Gunny. I don't have a Windows
directory there: it's WinNt!
</quibble>
 
V

Van T. Dinh

.... and Calc.exe is certainly not a DOS command or a DOS
prgram.

Van T. Dinh
MVP (Access)
 
V

Van T. Dinh

Try something like:

Shell "cmd.exe /K Dir C:\ && Type C:\cmd.txt",vbNormalFocus

The above command list the files (including the SubDirs in
C:\ and then print the text file C:\cmd.txt in the DOD
window.

HTH
Van T. Dinh
MVP (Access)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top