Running A Shell Command In VBA

R

R Tanner

Hi,

I'm trying to run the following shell command in VBA but it is telling
me the file is not found. My home directory when I bring up the
command prompt manually is C:\Documents and settings\robin.grossman,
which I think is the problem. What should I do?

Shell Environ$("COMSPEC") & "DEL Z:\Client Services\Operations
\PrintedVersion.pdf"
 
D

Dave Peterson

First, VBA has its own version to delete/erase.

Kill "z:\client services\operations\printedversion.pdf"

But you could try adding a space character in front of the "DEL" string:

Shell Environ$("COMSPEC") _
& " DEL Z:\Client Services\Operations\PrintedVersion.pdf"

But I bet you'll need to surround the filename with double quotes since it
contains spaces:

Shell Environ$("COMSPEC") _
& " DEL ""Z:\Client Services\Operations\PrintedVersion.pdf"""

(all untested)
 

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