Uncategorized

excel – issue regarding “Python script run in VBA crashes every times”


I was trying to run python script in VBA so that internal users can use to explore KPIs in the dashboard (excel as GUI and Python as backend).

The issue is that every time when the code runs to the last line, the spreadsheet just disappears without returning any error message, but when I run the script in PyCharm, the dashboard on Excel can got refreshed instantaneously. I really hope that I can run some help here; Highly Grateful!!!

The VBA code that I used to run python is as follows:

Sub RunPythonScriptWithXlwings()
' Specify the path to xlwings executable
Dim xlwingsPath As String
xlwingsPath = "C:\Users\rren\AppData\Local\Programs\Python\Python312\python.exe"

' Specify the path to your Python script
Dim scriptPath As String
scriptPath = "C:\Users\rren\OneDrive - MES\Desktop\Projects\52. MAR's report Python\mar_report.py"

' Construct the command to execute xlwings with the Python script
Dim command As String
command = """" & xlwingsPath & """ run """ & scriptPath & """"

' Use Shell to run the command
Shell command, vbNormalFocus
End Sub



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *