I have a macro saved as an xlsm file that I would like to use on a different Excel workbook. How can I do this using ActiveX?
This is the code for the workbook that I want to apply the macro to. What do I have to add on to this?
excelAll = actxserver('Excel.Application');Workbooks = excelAll.Workbooks;excelAll.Visible=1;excelAll.Workbooks.Open(filename);sheetnum=1;range='A1:ZZZ11041';Sheets = excelAll.ActiveWorkBook.Sheets;sheet1 = get(Sheets, 'Item', sheetnum);invoke(sheet1, 'Activate');Activesheet = excelAll.Activesheet;
I have already looked at this question (https://www.mathworks.com/matlabcentral/answers/58159-running-excel-macros-with-matlab-activex#answer_70392), but the solution provided can only be used to run a macro within the same workbook, not to run a macro on a different workbook.
Best Answer