I am running a c# 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?
我正在使用下面的代码行在Excel中运行c#console应用程序。代码工作正常。该过程大约需要20秒才能运行。我想知道如何让我的vba代码等待c#应用程序完成,然后继续执行此行之后的代码?
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)
1 个解决方案
#1
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)
#1
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)