|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Calling *.BAT file from VBA app
Hi,
I have a old-style dos bat file that I need to call from a VBA script. Not sure how to do - shell out to it? The VBA script is actually going to create the BAT file on the fly in a particular folder on the local machine and subsequently have it to execute. Lastly the BAT file will be deleted. Creating and deleting is no problem, but I am used to instantiating and using DLLS, not old time BAT files, so a little clueless.... thanks for any thoughts, fv |
|
#2
|
|||
|
|||
|
Look for wscript.shell
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
|||
|
|||
|
Thanks, Doug. Would something like:
dim ret as integer ret = Shell("C:\Directory\my.bat",1) work as well? thanks, fv |
|
#4
|
|||
|
|||
|
Quote:
Still looking for an answer.... So far I have: Code:
Dim Ws as Object
Dim batFileName as String
batFilename = "C:\Program Files\Blah\Blah.BAT"
Set Ws = CreateObject("WScript.Shell")
Ws.Exec (batFileName)
I don't seem to get any errors reported, but niether does the bat file seem to run. Any ideas? thanks, fv |
|
#5
|
||||
|
||||
|
There's no need to instantiate the Wscript Shell from VBA. Go back to your original code and change it slightly.
If you want to wait for your batch to complete before continuing, make sure it includes and END or EXIT and use this:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#6
|
|||
|
|||
|
Quote:
Ah, excellent information - thank you very much! I had to look for a dusty old book on MS-Dos stuck in a closet yesterday to even remember what a BAT file looked like! thanks again, FV |
|
#7
|
||||
|
||||
|
No problem at all. Glad I could help.
What exactly is your batch file doing? You can almost certainly do it all in VBA. |
|
#8
|
|||
|
|||
|
Quote:
Trying out some file compare software that does not have an ActiveX interface - you either run the software on the client via a GUI or you can run from command line: HTMLMATCH.EXE <originalFile> <revisedfile> <output file to show differences> Had a bunch of these to compare, so the VBA script reads through the directory of original files, gets the name of each and builds the BAT fly on the fly. Then it shells out and runs the BAT file and lastly deletes the BAT file. fv |
|
#9
|
||||
|
||||
|
You can do that in VBA, but you're probably saving yourself a lot of code work this way.
|
|
#10
|
|||
|
|||
|
Quote:
Yep - why reinvent the wheel. There are tons of compare utilities out there that will create a nice html output document highlighting differences between original and revised. fv |
|
#11
|
||||
|
||||
|
I agree. I generally try to avoid the use of third-party programs when I can help it, but that's just for portability reasons. In your case, I believe you're working with the best solution.
|
|
#12
|
|||
|
|||
|
Quote:
I understand that sentiment entirely. But project constraints will force one to use 3rd party components for some things that really would be a long project unto themselves to develop and perfect. I probably could write the file compares, file upload utilities for classic ASP, any file to PDF conversion utilities, etc. given a lot of time - but - when I need this working by next week and not next year, the choice is already made. And most of these 3rd party components are pretty well tried and true. fv |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Calling *.BAT file from VBA app |