Wait for powershell script for to finish it's execution

Tejas Kore

Board Regular
Joined
Nov 2, 2017
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Hi Friends,

I have called a powershell script in my vba code using "Call shell (..........".
I want to wait till it finishes it's execution.How can I do that ?
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi;

The below code, runs a batch file named "TCMB.bat" from Excel and when the user closes the batch file window, she/he is informed by a message box.

I hope, this helps.

Code:
Sub Test()
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.Shell")
    wsh.Run ThisWorkbook.Path & Application.PathSeparator & "TCMB.bat", 1, True
    MsgBox "Finnished ...."
End Sub
 
Upvote 0
Hi Haluk,

Thanks a LOT for replying.
Can you tell me where should I insert 'Call shell ....' line ?
Is TCMB.bat is acting like a timer ?
 
Upvote 0
I know I'm a bit late on this thread, but here is something that worked for me and perhaps it can help others that come across this thread:

Code:
Sub PowerShellWait()
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.Shell")
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    Dim errorCode As Integer
    wsh.Run "POWERSHELL.EXE " & "\\PathToYourPowerShellScript\PowerShellScript.ps1", windowStyle, waitOnReturn
    MsgBox "Finnished ...."
End Sub

Happy Coding!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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