I cannot get this simple python code to run by calling it with a VBA macro. Here is the python which writes a CSV to my desktop.
import pandas as pd string=['hello world','Sup'] DFstring=pd.DataFrame(string) DFstring.to_csv("C:/Users/Peter_K/Desktop/test.csv")
Next I attempt to call this code to action with this VBA code in excel.
Sub xls2py() Dim objShell As Object Dim PythonExe, PythonScript As String ChDir ActiveWorkbook.Path Set objShell = VBA.CreateObject("Wscript.Shell") PythonExe = """C:UsersPeter_Kanaconda3python.exe""" PythonScript = "C:UsersPeter_KDesktopUntitled3.py" objShell.Run PythonExe & PythonScript Set objShell = Nothing End Sub
A black box command prompt box flashes on the screen when I run this. But the CSV does not write. Can anyone figure out why this could be going wrong.
The problem here was two fold. First I was not importing numpy in my python script. Second I did not have my path set up correctly. A great and up to date video on how to do this is linked below.