Run Python Code with Excel VBA | #156

preview_player
Показать описание
In this video, I'll show you how to run a python code using Excel VBA.

The VBA code below is not mine. I found it in dozens and dozens of google searches and it's the same code. Remember to change the two variables inside the """ """"

#Python #ExcelVBA

Follow me on Twitter and Github @bjone6.

====================================
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 = """ """
PythonScriptPath = """ """

objShell.Run PythonExePath & PythonScriptPath

End Sub
Рекомендации по теме
Комментарии
Автор

hello thanks for the video tutorial, what if we want to specify python file in cell in the active workbook, so the user will just copy paste the path in the selected cell. thank you

agungwangsa
Автор

Hello, the program works when I run it in Python, but doesn't work with button

patje
Автор

I have anaconda and python installed but when I run this code the execution window is done automatically and returns me no results how to fix this please?

stephanetionfe
Автор

Hello, can we run a machine learning script to make predictions the same way?

sofianeikkour
Автор

that python script which is running how to stop that script using excel

djcannut
Автор

I am having a problem where the python window flashes and then the excel workbook crashes upon running the VBA code. Has anyone else encountered this error or know of a solution?

MooTheAlphaCow
Автор

Hi, its just open the shell window for 2 seconds, nothing else happened

tamirawad
Автор

Is it also possible to send a variable from Python to VBA ? Not necessarily to Excel but just to have the output variable of python script within VBA?

kimvandenhouten
Автор

It wasn't working for me. Tried twice😥

niranjanajunar
Автор

For some reason instead of the script running it opens the .py file as a notepad file

alejandrod.