I am workin on a python function to insert pictures into excel cells “In Cell Mode”.
The approach is using win32com package to start Excel create an excel file then run VBA codes.
I create a repo for anyone to test:
https://github.com/panzerkiller/insertPictureInCell.git
A strange behavior is encountered:
- Run the python code, error occures inside VBA run:
- Click “End” button, then “Cancel” to keep the excel open; now go to Developer tab and open the Macro editor, run the macro, same error occurs:
- Next, “End” the macro, go to “Review” tab, click either “Protect Sheet” or “Protect workbook”, then click “Cancel”:
- Now, go back to Macro editor and run the macro again, it works now:
- Thought: I search quite around and it seems that the “InsertPictureInCell” function is relatively new, refers to Microsoft Office 16.0 Object Library, is that a bug or I missed something important? Any suggestions are welcome and highly appreciated!
I tried to use ws.Shapes.AddPicture() function in VBA, it cannot put the picture “In Cell Mode”, which is required by my task.
I expect to run the InsertPictureInCell() in VBA macro via Python code.
2