Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interacting with buttons/macros inside excel automatically

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.

like image 959
cydan Avatar asked Jul 18 '17 17:07

cydan


People also ask

How do you trigger a macro automatically?

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.

How do I create an interactive button in Excel?

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.


1 Answers

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.

like image 70
Vasily Ryabov Avatar answered Oct 19 '22 02:10

Vasily Ryabov