Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2005, 12:24 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run .bat file from Excel VBA

I simply want to run a .bat file in DOS when I open an Excel file.

My .bat file collects all the .txt file names in a specific directory and stores file names that start with "HC" in one .txt file and file names that start with "HR" in another:

   cd c:\My Files\Junk
   dir HC*.txt /b > Catfiles.txt
   dir HR*.txt /b > Retfiles.txt

Afterwards, my Excel macro reads each of these files (Catfiles.txt and Retfiles.txt), gets the file names, and opens them one at a time.

Currently, I run the .bat file before I open the Excel file. I WOULD LIKE to launch the .bat file when I open my Excel file with some sort of "On Open" command.

Thank you. Harold Hawken



 
Old June 22nd, 2005, 12:33 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Use Shell "C:\My Files\Junk\MyBat.bat"

-vemaju

 
Old June 23rd, 2005, 03:03 PM
jjd jjd is offline
Authorized User
 
Join Date: May 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Implement this code in Workbook_Open. The /c closes the DOS prompt when finished.

Private Sub Workbook_Open()

Call Shell(Environ$("COMSPEC") & " /c C:\Path.bat", vbNormalFocus)

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA and The Bat! sektor Excel VBA 5 April 11th, 2008 06:12 AM
Run bat file as part of Setup project adorable.ashish General .NET 0 March 5th, 2008 07:42 AM
Run a MS DOS Batch file from Excel VBA Louh Excel VBA 1 March 4th, 2008 10:02 PM
Run VBA Excel File On Internet Explorer DHDang Excel VBA 0 November 12th, 2003 03:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.