Reputation: 183
I am wondering to use xlsxwriter to control my excel sheet instead of using old fashioned way by using VBA. I need a button to trigger some actions. What I read from the official documentation is
workbook.add_vba_project('./vbaProject.bin')
worksheet.insert_button('B3', {'macro': 'say_hello',
'caption': 'Press Me'})
I don't know how to define my own function as a macro and I don't know how to generate "vbaProject.bin". Is there anyway to write a macro in format like python function and directly assign it to the button?
If I must include the macro in vbaProject.bin, how can I do that? Hope it is not something like vba.
Upvotes: 2
Views: 981
Reputation: 1393
So you have many ways to control and automate your files:
You can use vba
You can use xlsxwriter which uses python syntax
You can use a library called PyXLL https://www.pyxll.com/docs/userguide/macros.html . It seems you are able to write a macro using python syntax but i haven't tried it, you could have a look as it might be what you are looking for.
About your question on how to inject a macro to your excel using xlsxwriter have a look at my answer here, i think it is quite detailed:
Add dataframe and button to same sheet with XlsxWriter
By the way vba is not hard to learn and there is a lot of information online. If you don;t want to write the code manually you can record the macro by pressing record, do your thing and stop the recording. Then you will have the code which you can inject it to your file (look at my tutorial above)
Upvotes: 1