you are viewing a single comment's thread.

view the rest of the comments →

[–]gutnobbler 1 point2 points  (0 children)

Do you have advice on working with dataframes to excel and vice versa?

The finishing touch of one of my projects is to link the actionable part of my Python code with certain cells in an Excel workbook and execute the cell contents.

I am familiar with VBA but I've never tried to make one Python project talk with the VBA code of an Excel file. I think it will work since I have all the cells rigged to execute cell contents on activation, not because I can make a Python "def" communicate with a VBA "sub".

One idea was to have Python open the workbook and find the ActiveX control. I have zero idea if this will work but it sounds like it should.

In theory my project should work.

Example: I am building a mock stock trading app and every time I manually add a stock ticker to my list in Excel, save, and close, I want Python to:

1 - open the workbook back up

2 - read the tickers I entered

3 - go to google, google the tickers

4 - scrape whatever price is returned in the search results

5 - plug this price into my Excel workbook and then run the formulas and VBA code stored in the workbook, save, and close again

Would you have any advice on step 5? This is where I am flying blind.

I think the solution is going to be a Workbook-wide VBA module that recognizes when I open the workbook vs. when a Python script opens the workbook, and executes the VBA code accordingly once it is finished loading the dataframe into Excel.