Run bat file from excel macro

B

bhs

Hi,

I have a bat file which renames the files in a folder. I am unable to
run this batch file from excel macros. Could anybody help me on this.

Thanks,
Santosh
 
B

bhs

Hi Jason,

I tried that but its not working. When just double click the bat file,
its working but not through excel macros.

Thanks,
santosh
 
B

bhs

Mike,

Even this does not work.
what i noticed was, when run this the cmd prompt is in "C:\Documents
and Settings\bhs\My Documents" but my batch file is in C:\.
I used the syntax like this :
Shell Environ("comspec") & " /k C:\ravinu.bat", vbNormalFocus
Where /k helped me freezing the cmd window.

Now i need to get the cmd prompt to "C:" and then execute the batch
file. Can you help me on this.

Thanks,
Santosh
 
C

Chip Pearson

Just a word of caution. Execution of any other code in your workbook will
not
wait until a shell command has completed it will continue.

You can make it wait. See http://www.cpearson.com/excel/shellandwait.htm .
This has two procedures: ShellAndWaitSimple, which just waits for the
process to end, just like every other ShellAndWait routine out there, and
ShellAndWaitEnhanced that lets you display messages to the user as the
shell'd program runs.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 

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