I have a problem calling python scripts from vba in excel, when I run the macro nothing happens!
I don't know exactly where the problem is?
my code in vba:
Option Explicit
Sub Run_python_script()
' declare the variables
Dim objShell As Object
Dim PythonExe, PythonScript As String ' the path of the python file and python script
' create a new shell object
Set objShell = VBA.CreateObject("Wscript.Shell")
'provide the file path to the python exe
PythonExe = """C:\Users\bbbbbb\AppData\Local\Microsoft\WindowsApps\python.exe"""
'provide the file path to the python script
PythonScript = """C:\Users\bbbbbb\OneDrive\Bureau\test_python\test.py"""
'run the python script
objShell.Run PythonExe & PythonScript
End Sub
I'm using python 3.7 and the jupyter ide
here is my python code :
import pandas as pd
import xlrd
file = r'C:\Users\bbbbbb\OneDrive\Bureau\test_python\test.xlsm'
sheetname='Feuil1'
n=2
df = pd.read_excel(file,skiprows=[*range(n)],index_col=[0])
df_static= df[['CF','VPC','CO','MA','status','Project Naming','Poste','family','ressource']]
wb = xlrd.open_workbook(file)
ws = wb.sheet_by_name(sheetname)
year = ws.cell(0,0).value
month = ws.cell(1,0).value
datetime_cols= pd.to_datetime(df.columns,dayfirst=True,errors='coerce')
out = (df.loc[:,(datetime_cols.year == year) & (datetime_cols.month == month)])
df_merge=pd.concat([df_static,out], axis=1)
df_merge
book = load_workbook(r'C:\Users\bbbbbb\OneDrive\Bureau\test_python\test.xlsm')
writer = pd.ExcelWriter(r'C:\Users\OneDrive\Bureau\test_python\test.xlsm', engine='openpyxl')
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
df_merge.to_excel(writer, "ETP",startcol=0,startrow=6)
writer.save()
my excel sheet 'Feuil1'looks like that :
and when I select the year and the month in cells A1 and A2 , it will generate another sheet called 'ETP' with the selected data.
so by importing the pyrhon script , each time I chose different dates , it will updated automaticaly
thanks in advance for your help

.xlsmworkbook that you run the macro? Your Python script can be erring out on a permission issue. Putting aside Excel, does the Python script successfully runs on its own (i.e., command line call in terminal).