MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2002, 06:22 PM   #1
Mechanic
 
Join Date: Mar 2002
Posts: 60
Default

What are the Excel Visual Basic command(s)I should use to Shell out to a DOS batch program? "Shell" doesn't seem to work.

Mechanic
Mechanic is offline   Reply With Quote
Old Apr 15th, 2002, 06:40 PM   #2
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

try
Sub RunPcDownloadprodreview() '
'
'
Dim TaskID As Long
Dim hProc As Long
Dim lExitCode As Long
Dim access_Type As Variant
Dim STILL_ACTIVE As Variant
Dim Program As Variant

access_Type = &H400
STILL_ACTIVE = &H103
ChDir (wkbname)
Program = wkbname & "filename.bat"
TaskID = Shell(Program, 1)
hProc = OpenProcess(access_Type, False, TaskID)
Do
GetExitCodeProcess hProc, lExitCode
DoEvents
Loop While lExitCode = STILL_ACTIVE

End Sub

this will hold the window open till the bat file finishes.
brettvba is offline   Reply With Quote
Old Apr 15th, 2002, 07:32 PM   #3
Mechanic
 
Join Date: Mar 2002
Posts: 60
Default

I tried the code you gave me and receive an error on OpenProcess command. It tells me that it doesn't recognize the function or Sub program.

Mechanic
Mechanic is offline   Reply With Quote
Old Apr 15th, 2002, 07:37 PM   #4
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

sorry mate add this to your code
at the top in the declarations
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
brettvba is offline   Reply With Quote
Old Apr 15th, 2002, 09:03 PM   #5
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
Default


How about something like this which uses the Shell function:

'


Dim sbatfilepath As String
Dim sBatFile As String


sBatFile = "test.bat"
sbatfilepath = "C:Temp"

ChDir sbatfilepath

'You might want to put a test in to make sure that the .bat file exists
If Environ("OS") <> "" Then
' It's NT
Shell "cmd /C " & sBatFile, 1
Else
' It's 95 or 98
Shell "COMMAND.COM /C " & sBatFile, 1
End If

End Sub '


HTH
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 16th, 2002, 12:02 PM   #6
Mechanic
 
Join Date: Mar 2002
Posts: 60
Default

Thank you, that worked.
Mechanic
Mechanic is offline   Reply With Quote
Old Apr 16th, 2002, 04:16 PM   #7
Mechanic
 
Join Date: Mar 2002
Posts: 60
Default

By the way,
What does the "COMMAND" part of the Shell statement look like for Windows 2000?

Mechanic
Mechanic is offline   Reply With Quote
Old Apr 16th, 2002, 04:20 PM   #8
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
Default

It's "cmd" as well. You can test this out by going to Start|Run (or WINDOWS KEY + R, if you want to be flash) and type in "cmd" into the run dialogue box.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Apr 16th, 2002, 04:38 PM   #9
Mechanic
 
Join Date: Mar 2002
Posts: 60
Default

What do the results of the Environ("OS")statement look like for Windows 2000?

Mechanic
Mechanic is offline   Reply With Quote
Old Apr 16th, 2002, 04:41 PM   #10
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
Default

Windows 2000 is also known as NT5, so Environ("OS") returns:


Windows_NT


MS are good at hitting their own deadlines and keeping naming conventions going, hence the two different names for the OS.

I'll need to test ME when I go home, but I'm pretty sure everything in the Win9x family, which ME is does not have Environment parameters. That's why the test is just Environ("OS")<>"".
_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-04-16 11:42 ]

[ This Message was edited by: Mark O'Brien on 2002-04-16 11:44 ]
Mark O'Brien is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes