VBA WaitOnReturn not working

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
518
Office Version
  1. 365
Platform
  1. Windows

Hi All,​

I require an external batch file to complete before continuing with the VBA code. Dr Google tells me plenty of different methods to achieve it. I have not had any success with any of them suggestions.

I particular followed a post on this message board by Jake975, with this (modified) code

VBA Code:
Sub DailyUpdate()
Dim strCommand As String, wsh As Object
Set wsh = CreateObject("Wscript.Shell")

'using Wscript
strCommand = Chr(34) & "C:\Users\jeff\OneDrive\Desktop\New Horses\PuntingForm_v18.exe" & Chr(34)
wsh.Run strCommand, 0, True

Sheet2.Range("AP11").Value = "Yes"
End Sub

The aim is to have a userform label update with a different colour after the external file has completed, so that I can see that, that particular routine completed correctly.

The change in colour works great. However, the WaitOnReturn parameter in this line:

wsh.Run strCommand, 0, True

is being ignored because I can that the value in Sheet2.Range("AP11").Value = "Yes" is being updated before the external file has even started.

Any ideas are greatly appreciated.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I have recently also tried this syntax, and got the same result.


VBA Code:
'using Wscript
strCommand = Chr(34) & "C:\Users\jeff\OneDrive\Desktop\New Horses\PuntingForm_v18.exe" & Chr(34)
lngErrorCode = wsh.Run(strCommand, 0, True)

    If lngErrorCode <> 0 Then
        MsgBox "Uh oh! Something went wrong with the batch file!"
        Exit Sub
    End If
 
Upvote 0

Forum statistics

Threads
1,215,274
Messages
6,123,998
Members
449,137
Latest member
abdahsankhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top