I am struggling to run vba macro activated through xlwings.
My macro is saved in ThisWorkbook area rather than a module. When I have used similar method with a macro saved in a Module it works ok.
PythonScript opens workbook and runs module. It then attempts to run another macro which is in different tab of the workbook.
import xlwings as xw
wb = xw.books.open(‘myworkbook’)
ExcelMacro = wb.macro(‘1stmacro’)
ExcelMacro()
#1stmacro located in a Module. #This works.
ExcelMacro = wb.macro(‘ThisWorkbook.2ndmacro’)
ExcelMacro()
#2nd macro is located in ThisWorkbook rather than Module. Full name is given by ThisWorkbook.2ndMacro where 2nd macro takes form 2ndMacro_Click. The button that is used to activate this is contained in different tab to the one that the workbook opens on.
When I save the workbook to open where this button is located it works; when it is saved on different tab other than this it does not work.
Any help would be greatly appreciated!