简体   繁体   中英

running c# console application from excel and wait for app to finish

I am running ac# console application from within Excel using the line of code below. The code is working fine. The process takes about 20 seconds to run. I was wondering how I get my vba code to wait for the c# application to finish before continuing execution of the code following this line?

I do not want to use a pause or similar function.

 Dim id As Integer
 id=Shell("""C:\MyFolder\bin\Debug\MyApp.exe"" /PARA1 " & p1 & " /PARA2 " & p2, vbNormalFocus)

You could try this code (inspired from this post ):

Dim id As Integer
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

id = wsh.Run("""C:\MyFolder\bin\Debug\MyApp.exe"" /PARA1 " & p1 & " /PARA2 " & p2, windowStyle, waitOnReturn)

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