Running python script using Outlook VBA

201 Views Asked by At

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 Management\Exstream_Reconciliation.py"

Shell(Path)

End Sub
3

There are 3 best solutions below

0
syed On BEST ANSWER

Ok this is the solution for anyone looking

Sub RunPyFileFromMacroViaCmd()
    Dim Path As String
    Dim filepath As String
    filepath = """C:\Doc Management\Exstream_Reconciliation.py"""
    Path = "cmd /k" & filepath
    Shell (Path)
End Sub
0
Eugene Astafiev On

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.

14
Dmitry Streblechenko On

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