简体   繁体   中英

Is there any way to run asynchronous methos in Excel Macro?

I am having trouble while running excel macros as it causes my UI to freeze.

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 here is that while running the above Run_Test method "oQTP.Run" takes some time to complete and during this time if click on excel sheet the UI freezes.

So is there any way i can run this method asynchronously and prevent the excel from freezing?

Or Is there any other technique to prevent this?

VBA itself does not provide any support for asynchronous programming. The programmer must explicitly call DoEvents within nested loops to allow the Windows Message Queue to be processed.

However, it is possible for a function library invoked by VBA to provide asynchronous calls. Classic ADO does by providing the option of specifying a query call as asynchronous, raising an event when the call has completed (either successfully or unsuccessfully).

If you require 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 into the resulting Assembly.

If your question is about running QTP asynchronously you can just specify False as the WaitOnReturn parameter of the Run method.

See this answer for further details .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM