VBA - shell

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2008
Posts: 21
Reputation: jammiedude is an unknown quantity at this point 
Solved Threads: 1
jammiedude's Avatar
jammiedude jammiedude is offline Offline
Newbie Poster

VBA - shell

 
0
  #1
Oct 16th, 2008
Hello, if anyone can help with this I would much appreciate it.

I am writing a macro within vba for excel, and i have successfully managed to use the shell command to call my batch file but, how would i program the rest of the macro to carry on when the batch file has finished?

The batch file currently has a pause at the bottom, but i removed this and the batch file just ended when finished would i be able to somehow use vba to check to see if the batch file is still running or something?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,146
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: VBA - shell

 
0
  #2
Oct 16th, 2008
using DOEVENTS just might help you .
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 21
Reputation: jammiedude is an unknown quantity at this point 
Solved Threads: 1
jammiedude's Avatar
jammiedude jammiedude is offline Offline
Newbie Poster

Re: VBA - shell

 
0
  #3
Oct 17th, 2008
Hello, many thanks for the reply i managed to find a function on the net, that was able to lock into a loop until the process was finished. which is:
visualbasic Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Type STARTUPINFO
  4. cb As Long
  5. lpReserved As String
  6. lpDesktop As String
  7. lpTitle As String
  8. dwX As Long
  9. dwY As Long
  10. dwXSize As Long
  11. dwYSize As Long
  12. dwXCountChars As Long
  13. dwYCountChars As Long
  14. dwFillAttribute As Long
  15. dwFlags As Long
  16. wShowWindow As Integer
  17. cbReserved2 As Integer
  18. lpReserved2 As Long
  19. hStdInput As Long
  20. hStdOutput As Long
  21. hStdError As Long
  22. End Type
  23.  
  24. Private Type PROCESS_INFORMATION
  25. hProcess As Long
  26. hThread As Long
  27. dwProcessID As Long
  28. dwThreadID As Long
  29. End Type
  30.  
  31. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  32. hHandle As Long, ByVal dwMilliseconds As Long) As Long
  33.  
  34. Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  35. lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  36. lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  37. ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  38. ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  39. lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  40. PROCESS_INFORMATION) As Long
  41.  
  42. Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  43. hObject As Long) As Long
  44.  
  45. Private Const NORMAL_PRIORITY_CLASS = &H20&
  46. Private Const INFINITE = -1&
  47.  
  48. Public Sub ExecCmd(cmdline$)
  49. Dim proc As PROCESS_INFORMATION
  50. Dim start As STARTUPINFO
  51. Dim ReturnValue As Integer
  52.  
  53. ' Initialize the STARTUPINFO structure:
  54. start.cb = Len(start)
  55.  
  56. ' Start the shelled application:
  57. ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
  58. NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  59.  
  60. ' Wait for the shelled application to finish:
  61. Do
  62. ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  63. DoEvents
  64. Loop Until ReturnValue <> 258
  65.  
  66. ReturnValue = CloseHandle(proc.hProcess)
  67. End Sub
Then all you do is call cmdline$ " " and pass the batch file location in the commas.

Many thanks!
Last edited by cscgal; Oct 17th, 2008 at 11:41 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 1427 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC