0

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?

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)
shruti1810
  • 3,920
  • 2
  • 16
  • 28
mHelpMe
  • 6,336
  • 24
  • 75
  • 150
  • 3
    Look at this question [excel-vba-wait-for-shell-command-to-complete](http://stackoverflow.com/questions/15951837/excel-vba-wait-for-shell-command-to-complete) – dePatinkin May 13 '15 at 13:39
  • 2
    Take a look at this thread: http://stackoverflow.com/questions/10279404/vbscript-how-to-make-program-wait-until-process-has-finished – mageos May 13 '15 at 13:43
  • thanks guys - both work – mHelpMe May 13 '15 at 13:57

1 Answers1

2

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)
Community
  • 1
  • 1
Sébastien Sevrin
  • 5,267
  • 2
  • 22
  • 39