![]() # Use the button's alt text as the message You can set a value as the AlternativeText for a button via the "Format Control." option on the button's context menu:Īnd in the macro we can retrieve that Alt Text as follows: from pyxll import xl_macro, xlcAlert, my_macro(): We might even have buttons with the same name that we want to use to call our macro with some different data.Īnother option is to use the "AlternativeText" property of the button. Using the button name isn't always convenient as we may want to pass some other information to the macro that is different from the button name. ![]() ![]() # Get the button object that called this macroīutton = xl.ActiveSheet.Shapes In the above example, instead of passing "message" as some text from the "Assign Macro" dialog we can get the button object that the macro was called from and show the button name: from pyxll import xl_macro, xlcAlert, my_macro(): Then, we can use properties on that button to determine how our macro behaves instead of passing an argument to the macro. We can use the Excel Object Model to access the button that the macro was called by (see Using Python as a VBA replacement). Instead, we have to use another way to achieve what we need. Unfortunately it is not possible to pass arguments from the "Assign Macro" dialog for a button to a shared macro function like the ones written using PyXLL. XlcAlert( message) Passing Data to a Macro from a Button It is possible to assign a macro written as a Python function to a button or other control in Excel by right clicking the control and selecting "Assign Macro" (see Calling macros from Excel)įor example, from pyxll import xl_macro, my_macro():īut what about if your macro needs one or more arguments and you want to pass those from the button to the macro? from pyxll import xl_macro, my_macro( message):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |