Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA: Shell() command to keep CMD after execution completes

I am executing a .py python script from VBA using the Shell()

Sub Run_Python()
    
    Dim PYTHON_FULL_PATH, PYTHON_SCRIPT_PATH As String   
    iRowNo = 2
    Do Until Sheet7.Cells(iRowNo, 1) = ""
        PYTHON_FULL_PATH = Sheet7.Cells(iRowNo, 1)
        PYTHON_SCRIPT_PATH = Sheet7.Cells(iRowNo, 2)
    
        iRowNo = iRowNo + 1
    Loop
    
    RetVal = Shell(PYTHON_FULL_PATH & " " & PYTHON_SCRIPT_PATH, vbNormalFocus)
    

End Sub

The Python script prints few lines as part of the code and those print statements are shown in the CMD prompt.

But once the execution completes or errored our the CMD gets closed automatically.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to keep the CMD prompt visible even after the execution gets completed ?

Thanks,

>Solution :

Run cmd.exe with /k parameter:

RetVal = Shell("cmd /k " & PYTHON_FULL_PATH & " " & PYTHON_SCRIPT_PATH, vbNormalFocus)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading