I'm trying to find a way to make a python script that finds all the buttons/checkboxes inside an excel document and interacts with them randomly.
I've tried using pywinauto, but it doesn't find the actual objects inside the document (probably because it's a vb object and not a regular GUI).
How can it be done using python? Or maybe there's another way to do it?
Here is a file for example excel
Thanks.
Steps to run macro automatically when the workbook opens:Step 1: Go to the developer's menu and then go to the visual basic. Step 2: Go to ThisWorkbook Tab. Step 3: Write down Private Sub Workbook_open() and hit enter.
Insert the Option ButtonsClick the Developer tab on the Ribbon. Click the Insert button in the Controls group. Click on the Option Button under the Form Controls header. Click on the spreadsheet where you want to position the control and repeat this step for the number of option buttons that you need.
Thanks for the sample! I'm afraid there is no nice way to obtain button or check box texts using pywinauto. Though Inspect.exe
shows these controls but they all are just images! See the screenshot with Inspect.exe. So the only way to automate them is enumerating by index. Of course, you must use pywinauto.Application(backend="uia")
. For random interaction the texts might not matter, but the texts would be very helpful for re-contructing the actions sequence in case of crash/error.
Another chance might be in win32com.client
usage. Not sure Excel COM objects have necessary properties. Need to investigate separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With