Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Launch a .bat file with VBA

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Launch a .bat file with VBA

It does work with Bat and Cmd files. These are considered executables.

--
Regards,
Tom Ogilvy



" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Launch a .bat file with VBA

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Launch a .bat file with VBA

Thanks for the reply. It's still not running correctly. I assume the
C:\x.bat in your example is the file location and filename? What does
the /c do? Thanks.

Gary''s Student wrote:
For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Launch a .bat file with VBA

I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Launch a .bat file with VBA

Thanks Tom. That seems to run the batch file, but the results of the
batch file don't seem to be happening. I looked up the shell command in
the help file and saw the following note:

Note By default, the Shell function runs other programs
asynchronously. This means that a program started with Shell might not
finish executing before the statements following the Shell function are
executed.

Do you think it's possible that I am not getting my results because the
MS-DOS command prompt window is being closed before it's finished
executing the batch file?

Thanks.

Tom Ogilvy wrote:
I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Launch a .bat file with VBA

It depends on how you define getting the results

Once the shell command is executed, the vba code continues on. The bat file
is running in another thread disconnected from the vba code. What are you
trying to accomplish and how are you trying to use the results of the bat
file.

--
Regards,
Tom Ogilvy


" wrote:

Thanks Tom. That seems to run the batch file, but the results of the
batch file don't seem to be happening. I looked up the shell command in
the help file and saw the following note:

Note By default, the Shell function runs other programs
asynchronously. This means that a program started with Shell might not
finish executing before the statements following the Shell function are
executed.

Do you think it's possible that I am not getting my results because the
MS-DOS command prompt window is being closed before it's finished
executing the batch file?

Thanks.

Tom Ogilvy wrote:
I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Launch a .bat file with VBA

The bat file takes a grouping of binary files in a folder and combines
them then deletes the original binary files. When I run the bat file
just by double clicking it in the folder, it works fine, but when I try
to run it through my VBA code, I see the MS-DOS windown come up and it
looks like it runs fine, but then the old binary files are there
untouched.

Tom Ogilvy wrote:
It depends on how you define getting the results

Once the shell command is executed, the vba code continues on. The bat file
is running in another thread disconnected from the vba code. What are you
trying to accomplish and how are you trying to use the results of the bat
file.

--
Regards,
Tom Ogilvy


" wrote:

Thanks Tom. That seems to run the batch file, but the results of the
batch file don't seem to be happening. I looked up the shell command in
the help file and saw the following note:

Note By default, the Shell function runs other programs
asynchronously. This means that a program started with Shell might not
finish executing before the statements following the Shell function are
executed.

Do you think it's possible that I am not getting my results because the
MS-DOS command prompt window is being closed before it's finished
executing the batch file?

Thanks.

Tom Ogilvy wrote:
I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Launch a .bat file with VBA

Maybe when you run the .bat, it expects the files that it works on to be in the
same folder.

Maybe, you can add commands to go to that drive and folder to the top of the
..bat file:

@echo off
c:
cd C:\yourfolderhere
....

=====
Or maybe the .bat file isn't finishing quickly enough. You could use a method
to wait for the .bat file to finish--or you could just estimate how long it
takes and pause your macro a bit.

'shell to the .bat file
application.wait now+timeserial(0,0,10)
'(for 10 seconds)





wrote:

The bat file takes a grouping of binary files in a folder and combines
them then deletes the original binary files. When I run the bat file
just by double clicking it in the folder, it works fine, but when I try
to run it through my VBA code, I see the MS-DOS windown come up and it
looks like it runs fine, but then the old binary files are there
untouched.

Tom Ogilvy wrote:
It depends on how you define getting the results

Once the shell command is executed, the vba code continues on. The bat file
is running in another thread disconnected from the vba code. What are you
trying to accomplish and how are you trying to use the results of the bat
file.

--
Regards,
Tom Ogilvy


" wrote:

Thanks Tom. That seems to run the batch file, but the results of the
batch file don't seem to be happening. I looked up the shell command in
the help file and saw the following note:

Note By default, the Shell function runs other programs
asynchronously. This means that a program started with Shell might not
finish executing before the statements following the Shell function are
executed.

Do you think it's possible that I am not getting my results because the
MS-DOS command prompt window is being closed before it's finished
executing the batch file?

Thanks.

Tom Ogilvy wrote:
I am sure that works, but this worked fine for me as well:

Sub EFG()
Shell "C:\Data2\mybat.bat"
End Sub

--
Regards,
Tom Ogilvy



"Gary''s Student" wrote:

For example:

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


CMD "understands" what to do with .bat files
--
Gary's Student


" wrote:

Is there a way to launch a .bat file in VBA? I have read to use the
shell command to launch programs, but that doesn't seem to be working
so I'm not sure that it works for anything other than executables? Is
there any way to do this? Thanks much!

Nick





--

Dave Peterson
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
Launch Program then load file Keyrookie Links and Linking in Excel 1 March 1st 10 11:45 PM
xls file will not launch atlantic grouper Excel Discussion (Misc queries) 7 May 7th 09 04:20 PM
2007 Excel will not launch from file Barbara Excel Discussion (Misc queries) 2 July 31st 08 06:36 PM
File won't launch eric blom Excel Discussion (Misc queries) 1 September 17th 07 10:30 PM
Macro launch - Button vs Manual launch , has different results. Wayne Excel Programming 4 February 23rd 05 11:33 AM


All times are GMT +1. The time now is 09:49 PM.

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"