[Python] Creating a button in Excel to Run Python Script

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    Hi Everyone I coded a python script in which i am taking values from Excel sheet and creating a new text file and writing the Excel values into that Text file. So I want to create a excel Button through Macro/VBA(As I have never worked with these two) in which on pressing the Button It run My Python script and give output of the created Text file. I tried with some basic code but it is only Executing and not giving any output. Currently I am running My Python Script in Spider IDE.

    Sub RunPythonScript()

    Dim objShell As Object
    Dim PythonExe, PythonScript As String

    'Create a shell object
    Set objShell = VBA.CreateObject("Wscript.shell")

    PythonExe = """C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8\Python
    3.8 (32-bit)"""
    PythonScript = """C:\Users\user\.spyder-py3\temp.py"""

    objShell.Run PythonExe & PythonScript

    End Sub


    EDIT: The error I am getting is enter image description here

    Continue reading...

Compartilhe esta Página