Is there a way to run an asynchronous method in an Excel macro?

I am having problems working with excel macros as it makes my UI get stuck.

Consider the following code:

Call Run_Test()

Sub Run_Test()

Set oQTP= CreateObject("Quicktest.Application")

oQTP.Open "<Test Path>"
oQTP.Run"<Test Path>"

End Sub

      

The problem is that when running the above Run_Test method "oQTP.Run" it takes some time to complete and during this time, if you click on the excel sheet, the UI hangs.

So is there any way to run this method asynchronously and prevent excel from freezing?

Or is there any other way to prevent this?

+3


source to share


2 answers


VBA itself does not provide support for asynchronous programming. The programmer must explicitly call DoEvents inside nested loops to enable Windows message queue processing.

However, it is possible that a library of functions called by VBA provides asynchronous calls. The classic ADO does by providing the ability to specify a request call as asynchronous by raising an event when the call succeeds or fails.



If you need custom code to run asynchronously, you will have to code it in an environment that provides such support, such as C # or VB.NET, and call it into the resulting assembly.

+3


source


If your question is about running QTP asynchronously, you can simply specify False

as a WaitOnReturn

method parameter Run

.



See this answer for more details .

+2


source







All Articles