How To Execute A Python Script From Excel Using VBA | Step-by-Step Tutorial [EASY]

Published: 27 July 2020
on channel: Coding Is Fun
97,224
1.5k

👉 Explore All My Excel Solutions: https://pythonandvba.com/solutions

𝗗𝗘𝗦𝗖𝗥𝗜𝗣𝗧𝗜𝗢𝗡
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
In this tutorial, I will show you, how to execute a Python script from Excel by using VBA.
If you do not have any experience in VBA, do not worry. To run a python script in VBA is very easy and I will explain every step.

Download the Excel File (incl. VBA code) & the Python Script of this video here [Google Drive]:
► http://bit.ly/3usrDoZ

To execute a Python script from Excel using different virtual environments [which also works on macOS], feel free to check out the following tutorial:
►    • Combine Excel & Python | Execute a Python ...  


🚩 Please find below the VBA Code:
_____________________________________________________________

Sub RunPythonScript()

Dim objShell As Object
Dim PythonExePath as String, PythonScriptPath As String
ActiveWorkbook.Save
ChDir ActiveWorkbook.Path

Set objShell = VBA.CreateObject("Wscript.Shell")

'PythonExePath = """ Insert Path to Python EXE here """
'PythonScriptPath = """ Insert Path to Python SCRIPT here """

objShell.Run PythonExePath & PythonScriptPath

End Sub
_____________________________________________________________

𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🔗 LinkedIn:   / sven-bosau  
📬 Contact: https://pythonandvba.com/contact

☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲?
If you want to support this channel, you can buy me a coffee here:
▶ https://pythonandvba.com/coffee-donation


On this page of the site you can watch the video online How To Execute A Python Script From Excel Using VBA | Step-by-Step Tutorial [EASY] with a duration of hours minute second in good quality, which was uploaded by the user Coding Is Fun 27 July 2020, share the link with friends and acquaintances, this video has already been watched 97,224 times on youtube and it was liked by 1.5 thousand viewers. Enjoy your viewing!