Running python script using Outlook VBA

Question:

Im trying to run a python script using Outlook Vba. When I run the below code. A python icon appears in the taskbar for a second and disappears. When in fact it should open a dialogue box and prompt me to enter folder name. After which it should run the rest of the script as usual.

Please help me run this script from outlook as I regularly do by double clicking the .py file.

Sub runpythonscript()

Dim Path As String

Path = "python C:Doc ManagementExstream_Reconciliation.py"

Shell(Path)

End Sub
Asked By: syed

||

Answers:

VBA (nor Outlook) doesn’t provide anything for debugging such cases. The best what you could do is to add log statements to the python script where you could output everything what happens in the code. Analyzing log files you will be able to figure the cause of the problem.

Answered By: Eugene Astafiev

You have a space in the file name. It must be quoted.

Ok this is the solution for anyone looking

Sub RunPyFileFromMacroViaCmd()
    Dim Path As String
    Dim filepath As String
    filepath = """C:Doc ManagementExstream_Reconciliation.py"""
    Path = "cmd /k" & filepath
    Shell (Path)
End Sub
Answered By: syed
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.