![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2002
Posts: 60
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
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. |
|
|
|
|
|
#3 |
|
Join Date: Mar 2002
Posts: 60
|
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 |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
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 |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
|
How about something like this which uses the Shell function: '
HTH |
|
|
|
|
|
#6 |
|
Join Date: Mar 2002
Posts: 60
|
Thank you, that worked.
Mechanic |
|
|
|
|
|
#7 |
|
Join Date: Mar 2002
Posts: 60
|
By the way,
What does the "COMMAND" part of the Shell statement look like for Windows 2000? Mechanic |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
|
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.
|
|
|
|
|
|
#9 |
|
Join Date: Mar 2002
Posts: 60
|
What do the results of the Environ("OS")statement look like for Windows 2000?
Mechanic |
|
|
|
|
|
#10 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,510
|
Windows 2000 is also known as NT5, so Environ("OS") returns:
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 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|