Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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. |
#6
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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. |
#7
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
executing a macro within another | Excel Discussion (Misc queries) | |||
Forumlas Not Executing | Excel Discussion (Misc queries) | |||
Executing queries stored in database in Excel | Excel Discussion (Misc queries) | |||
code sample for executing a VB function in Excel using perl | Excel Worksheet Functions | |||
Executing of excel Macros. | Excel Discussion (Misc queries) |