943,879 Members | Top Members by Rank

Ad:
Oct 16th, 2008
0

VBA - shell

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
jammiedude is offline Offline
32 posts
since Jun 2008
Oct 16th, 2008
0

Re: VBA - shell

using DOEVENTS just might help you .
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Oct 17th, 2008
0

Re: VBA - shell

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
Reputation Points: 10
Solved Threads: 1
Light Poster
jammiedude is offline Offline
32 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to make it Multiuser Programme
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: A media player to avoid exporting.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC