Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 22nd, 2005, 12:24 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old June 22nd, 2005, 12:33 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: , , Finland.
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

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

-vemaju

Reply With Quote
  #3 (permalink)  
Old June 23rd, 2005, 03:03 PM
jjd jjd is offline
Authorized User
 
Join Date: May 2005
Location: , , .
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


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



All times are GMT -4. The time now is 04:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.