Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

To achieve multithreading, I'm writing using VBA to construct VBScript code (VBStr) and write to file on-the-fly, before launching these helper scripts asynchonously:

Dim VBFile As Object
Dim VBPath As String
VBPath = CurrentProject.Path & "\" & GUID() & ".vbs"
Set VBFile = CreateObject("Scripting.FileSystemObject").CreateTextFile(VBPath)
VBFile.WriteLine VBStr
VBFile.Close

Dim Shell As Object
Set Shell = CreateObject("Wscript.Shell")

Shell.Run """" & VBPath & """"

However, how to control these scripts back in VBA? I can't seem to get a handle or reference to them. Say I want to terminate hung/stalled scripts after 60secs - how to do this?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Use .Exec instead of .Run. The returned WshScriptExec Object has methods/properties to monitor the status of and to terminate the process.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.