You should already have Excel running with the PyXLL add-in loaded at this stage. This will attach the debugger to the Python interpreter running in Excel. Type”EXCEL.EXE” into the drop down to find and select the Excel process. Once you have selected “Attach using Process ID” you will next be shown a list of running processes. Select the already running Excel process to attach to When prompted to select a debugger select “Python”, and then for the debug configuration select “Attach using Process ID”. Click that to create your first run configuration. If you do not have any Run Configurations yet you will instead see a blue button “Run and Debug”. If you already have some Run Configurations set up for your project then instead click the down arrow to the right of the currently selected run configuration and select “Add Configuration…”. Use the VS Code Run and Debug screen to connect to Python in Excel To start debugging click the “Run and Debug” button in VS Code. The VS Code debugger is capable of attaching to the Python interpreter that PyXLL runs inside of Excel. Unlike running a Python script from VS Code, we will be attaching VS Code to our already running Excel process. Whichever method of calling Python code from Excel you choose, you can use VS Code to debug your Python functions in Excel! Debugging Python in Excel with VS Code PyXLL supports calling Python from Excel in many other ways too, for example: Alternatively, take a look at our video tutorial Writing Excel Functions in Python. If you are new to calling Python in Excel with PyXLL then I would recommend this Introduction to Excel Worksheet Functions in Python page from the PyXLL documentation. To make your Python function callable in Excel you only need to add the decorator to it. The most common way is to write an Excel worksheet function (or UDF) in Python. There are many different ways to call Python in Excel using PyXLL. Once you have installed and familiarised yourself with VS Code you are ready to debug your Python code in Excel! Calling a Python function from Excel See the following link for the VS Code Python debugger documentation: If you are new to developing Python code in VS Code, there is a tutorial available here: If you don’t already have VS Code and the Python extension then you can download them from these links:
0 Comments
Leave a Reply. |