Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Executing a bat file from Excel

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


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,886
Default Executing a bat file from Excel

Hi

Shell("cmd.exe /c test.bat")

worked fine for me and ran test.bat in C:\Windows\System32
Give the full path of where your file is located
Ensure you have Exit as the last line of your bat file to return back to
Excel

--
Regards

Roger Govier


"Mr BT" wrote in message
news:kcNUh.83463$aG1.33381@pd7urf3no...
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



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Executing a bat file from Excel

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



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Executing a bat file from Excel

Thanks to both of you.
I forgot to mention, in order for this to work the way I need it to, I need,
I guess, a sendkeys command for the batch file to hit ENTER twice before it
closes.
Is this possible?

Thanks again

Mr BT



"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





  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Executing a bat file from Excel

I don't know.....maybe a pair of empty echos???
--
Gary''s Student - gsnu200715


"Mr BT" wrote:

Thanks to both of you.
I forgot to mention, in order for this to work the way I need it to, I need,
I guess, a sendkeys command for the batch file to hit ENTER twice before it
closes.
Is this possible?

Thanks again

Mr BT



"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








  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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





  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default Executing a bat file from Excel

Gary''s Student wrote...
I don't know.....maybe a pair of empty echos???

....

Yup.

"Mr BT" wrote:

....
I forgot to mention, in order for this to work the way I need it
to, I need, I guess, a sendkeys command for the batch file to hit
ENTER twice before it closes.


Macro could be

Sub foo()
Dim x As Variant
x = Shell(Environ("COMSPEC") & _
" /c (echo/&echo/) | ""x:\what\ever.bat""")
End Sub

Peruse the Google Groups archive for the alt.msdos.batch.nt newsgroup
if curious why this particular form for echo is optimal.

Also, FWIW, no exit statement is necessary in the batch file. The
console window will close when the batch file ends. You only need
explicit exit commands when exiting before reaching the end of the
batch file.

Also note that batch files launched this way will run asynchronously,
i.e., the Excel macro that launches it won't wait for the batch file
to end before it continues past the Shell call.

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Executing a bat file from Excel

I shell to CMD because its smart enough to know all the file associations.
This means that I can shell to a filename instead of an application as long
as I have set the association corrrectly.

For example, if I open a PDF file and the computer has the full Acrobat
installed the file opens. If only the Reader is installed, the file still
opens, but with just the Reader. Checkout Harlan's comments - they are
valuable,
--
Gary''s Student - gsnu200715
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 20
Default Executing a bat file from Excel

empty echos?
Could you explain how I could include this in the vb script?

Thanks

MrBT
"Harlan Grove" wrote in message
ps.com...
Gary''s Student wrote...
I don't know.....maybe a pair of empty echos???

...

Yup.

"Mr BT" wrote:

...
I forgot to mention, in order for this to work the way I need it
to, I need, I guess, a sendkeys command for the batch file to hit
ENTER twice before it closes.


Macro could be

Sub foo()
Dim x As Variant
x = Shell(Environ("COMSPEC") & _
" /c (echo/&echo/) | ""x:\what\ever.bat""")
End Sub

Peruse the Google Groups archive for the alt.msdos.batch.nt newsgroup
if curious why this particular form for echo is optimal.

Also, FWIW, no exit statement is necessary in the batch file. The
console window will close when the batch file ends. You only need
explicit exit commands when exiting before reaching the end of the
batch file.

Also note that batch files launched this way will run asynchronously,
i.e., the Excel macro that launches it won't wait for the batch file
to end before it continues past the Shell call.



  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default Executing a bat file from Excel

"Mr BT" wrote...
empty echos?


Console commands that produce only newlines, which when redirected to
the batch file via a pipeline would be processed by the batch file in
exactly the same way as pressing [Enter].

The point is you don't need to use SendKeys from Excel to the console
window. The command that launches the batch file can simulate pressing
[Enter] twice during batch file execution as long as you want fully
NONINTERACTIVE batch file execution.

Could you explain how I could include this in the vb script?


See my previous post.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
executing a macro within another brian Excel Discussion (Misc queries) 3 July 5th 06 01:22 AM
Forumlas Not Executing Trey Excel Discussion (Misc queries) 2 January 25th 06 04:02 PM
Executing queries stored in database in Excel John B Excel Discussion (Misc queries) 0 December 15th 05 09:08 AM
code sample for executing a VB function in Excel using perl newOLE Excel Worksheet Functions 7 August 10th 05 10:26 PM
Executing of excel Macros. KarthikK Excel Discussion (Misc queries) 4 June 28th 05 12:00 PM


All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"