The python script that I have written works in VS Code. it both writes to the terminal when prompted as well as writes a new excel file (which is the goal). However, when run in excel, the script runs and then does not do anything. The terminal flashes but the code does not execute
When attempting this from excel, I have ensured that all excel files (and even vs code) were closed. The macro to run the code is in a separate file. What am I missing? Thanks!
Python
import pandas as pd
import nameSplitter
Names = nameSplitter
to_drop = ['Question 2']
Names.df.drop(columns=to_drop, inplace=True)
sortedValues = Names.df.loc[Names.df['School Site'] == 3].sort_values('Question 1')
sortedValues.to_excel('sortedValues.xlsx', index=None)
VBA
Sub RunPythonScript()
'Procedure to run a Python Script in a VBA Procedure using the shell
'Declaration
Dim objShell As Object 'For the Shell
Dim Pythonexe, PythonScript As String
'Create the Shell Object
Set objShell = VBA.CreateObject("Wscript.Shell")
Pythonexe = """C:\Users\natha\AppData\Local\Programs\Python\Python310\python.exe""" 'path of the python.exe
PythonScript = "C:\Users\natha\OneDrive\Desktop\form-filters-master\form-filters-master\project\QuantitativeData.py" 'path of your Python script
'Run your Python script
objShell.Run Pythonexe & " " & PythonScript 'run takes two arguments
End Sub