Setting up your editor to allow Python code debugging for functions called from Excel can be tricky, depending on the details of your editor and linking software, but using the Visual Studio Code Editor and Pyxll, this works for me:
- Open the Python code in the Visual Studio Code editor.
- Make sure the Python code Extension is installed (check under File-Preferences-Extensions).
- Open the folder containing the code file. Either use File-Open Folder …, or click on the Explorer icon (top icon on the left hand icon bar).
- Go to the Excel File that will be calling the Python functions, and link to the editor from the Add-ins – Pyxll – Attach to VS Code menu:
- Return to Visual Studio Code and click the Run icon in the left hand tool bar …
- … then click the green arrow between Run and Python Attach. The blue bar at the bottom of the screen should turn orange:
- Finally click in the left hand margin on a line where you like to insert a break point …
- … and return to Excel and call the routine to be de-bugged.
The code will stop at the selected break point. You can then step through the code using the Run menu, use the function key short-cuts, or right click for debug options.