Executing shell commands in VBA

A

Abhishek

Hi,
Does anybody know how to execute shell commands such as "copy" in VBA.

Thanks,
Abhishek.
 
V

Vince

Simplest method is:

Dim a As String
a = "c:\windows\system32\xcopy c:\wf.exe c:\aa.exe "
Shell (a)
 
V

Vince

BTW, FWIW, I would rather use the filesystemobject to do file manipulation
like copying, deleting and renaming files than shell system commands.
 
M

Michael Bednarek

Does anybody know how to execute shell commands such as "copy" in VBA.

By invoking your shell with the appropriate arguments.

Assuming that it's the command COPY of CMD.EXE you desire to execute,
the command might look like:
Shell ("cmd /c copy source.dat target.dat")
For details see CMD /? from a CMD prompt.

However, as Vince suggested, methods native to VBA are probably
preferrable.
 

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