I found the following article that sort of fixed "powershell" execution to process waiting...
Determine when a shelled process ends in VBA
But i also launch macros that have only VBA code, and i would like to use the ExecCMD to wait for VBA code to finish as well, or place it in a process which wait for and only continue once it is finished.
Is it possible to run a VBA macro in Excel, as the process?
I have a "RUN-MACRO" that execute several sections.
For instance first section is to collect login information to authenticate as admin:
Call RUN_LOGIN_SAVE_TO_FILE
It is then able to put the called command into a job as this, and it will wait for user to input info, and then process that info, before it moves on..:
Sub RUN_LOGIN_SAVE_TO_FILE()
ExecCmd "powershell.exe H:\Temp\PublicFolder-powershell\Login.ps1"
End Sub
So all this works well, as long as i call an "external" function to run, like powershell or another program.
But the next section of the script is a macro running a VBA code:
Call BID_1_TextOut
Which is as follows:
Sub BID_1_TextOut()
Dim fso As New FileSystemObject
Dim Stream As TextStream
Dim RowNum As Long
RowNum = 1
' Create a TextStream.
Set Stream = fso.CreateTextFile(Split(Application.ActiveWorkbook.FullName, ".")(0) & "_Merge1.txt", True)
Application.Goto (ActiveWorkbook.Sheets("Merge1").Range("A1"))
'write columns A-E into a file for each line stopping when column A is empty
Do Until IsEmpty(Range("A" & RowNum)) = True
Stream.WriteLine Range("A" & RowNum).Value & Range("B" & RowNum).Value & _
Range("C" & RowNum).Value & Range("D" & RowNum).Value & Range("E" & RowNum).Value & _
Range("F" & RowNum).Value & Range("G" & RowNum).Value & Range("H" & RowNum).Value & _
Range("I" & RowNum).Value & Range("J" & RowNum).Value & Range("K" & RowNum).Value & _
Range("L" & RowNum).Value & Range("M" & RowNum).Value & Range("N" & RowNum).Value & _
Range("O" & RowNum).Value & Range("P" & RowNum).Value & Range("Q" & RowNum).Value & _
Range("R" & RowNum).Value & Range("S" & RowNum).Value & Range("T" & RowNum).Value & _
Range("U" & RowNum).Value & Range("V" & RowNum).Value & Range("W" & RowNum).Value & _
Range("X" & RowNum).Value & Range("Y" & RowNum).Value & Range("Z" & RowNum).Value & _
Range("AA" & RowNum).Value & Range("AB" & RowNum).Value & Range("AC" & RowNum).Value & _
Range("AD" & RowNum).Value & Range("AE" & RowNum).Value & Range("AF" & RowNum).Value & _
Range("AG" & RowNum).Value & Range("AH" & RowNum).Value & Range("AI" & RowNum).Value & _
Range("AJ" & RowNum).Value & Range("AK" & RowNum).Value & Range("AL" & RowNum).Value & _
Range("AM" & RowNum).Value & Range("AN" & RowNum).Value & Range("AO" & RowNum).Value & _
Range("AP" & RowNum).Value & Range("AQ" & RowNum).Value & Range("AR" & RowNum).Value & _
Range("AS" & RowNum).Value & Range("AT" & RowNum).Value & Range("AU" & RowNum).Value & _
Range("AV" & RowNum).Value & Range("AW" & RowNum).Value & Range("AX" & RowNum).Value & _
Range("AY" & RowNum).Value & Range("AZ" & RowNum).Value & Range("BA" & RowNum).Value & _
Range("BB" & RowNum).Value & Range("BC" & RowNum).Value & Range("BD" & RowNum).Value & _
Range("BE" & RowNum).Value & Range("BF" & RowNum).Value & Range("BG" & RowNum).Value & _
Range("BH" & RowNum).Value & Range("BI" & RowNum).Value & Range("BJ" & RowNum).Value & _
Range("BK" & RowNum).Value & Range("BL" & RowNum).Value & Range("BM" & RowNum).Value & _
Range("BN" & RowNum).Value & Range("BO" & RowNum).Value & Range("BP" & RowNum).Value & _
Range("BQ" & RowNum).Value & Range("BR" & RowNum).Value
RowNum = RowNum + 1
Loop
'close stream
Stream.Close
End Sub
How can i use ExecCMD to run this macro containing VBA code as a process/job as well, where it wait for it to finish before continue?