View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roger Govier Roger Govier is offline
external usenet poster
 
Posts: 2,886
Default Executing a bat file from Excel

Hi Gary

x = Shell("cmd.exe /c C:\testfile.bat", 1)


I have never actually shelled out to CMD to carry out a task before, but
find it interesting
I can see that the x= and the ,1 allows CMD to take the focus.
With mine, which I only tested from the Immediate window, I had to
manually select the CMD window.

Had my bat file been anything other than the simple "Hello world",
Pause, (which did require a user input), I had assumed that it would
have executed and returned focus back to Excel VBE anyway.

Is this correct, or should one always use the format you show?

--
Regards

Roger Govier


"Gary''s Student" wrote in
message ...
Sub Macro1()
x = Shell("cmd.exe /c C:\testfile.bat", 1)
End Sub
--
Gary''s Student - gsnu200715


"Mr BT" wrote:

I would like to use a customized menu with a macro that will execute
a batch
file.
I have read over http://www.mvps.org/dmcritchie/excel/shell.htm but I
don't
believe this is what I need.

Thank you.

MrBT