4

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.