How to run a macro saved in a different workbook using activeX

1 view (last 30 days)
I am using a GUI to analyse data and create a spreadsheet. I then have a macro that carries out further analysis/formatting on the data, and I'd like to include executing that macro in the GUI. This macro is saved in a different spreadsheet and I can't work out how to run the macro in a different spreadsheet. Any help would be greatly appreciated.
The macro is reasonably involved and I would really rather not try to re-write it in matlab, I'd much prefer to use activex to run it.

Answers (1)

Image Analyst
Image Analyst on 28 Aug 2013
Did you search this forum for "excel macro activex"? Try this link where I posted an answer: http://www.mathworks.com/matlabcentral/answers/58159#answer_70392
  2 Comments
Varun Lakshmanan
Varun Lakshmanan on 15 Jul 2019
I tried the link you attached, but it didn't work for me. Your answer only works if you are trying to run a macro in the same workbook, rather than running a macro in a different workbook. I've asked a similar question here: https://www.mathworks.com/matlabcentral/answers/471815-how-to-run-macro-in-a-different-workbook
Image Analyst
Image Analyst on 15 Jul 2019
Correct of course. That's because each workbook has its own macros stored with it. If you don't want to run a macro stored with the workbook then you'll have to essentially do the macro you want with your activeX code from MATLAB. Like if workbook1 has macros mac1 and mac2, and workbook2 has macros mac3 and mac4, but you want to do your own custom code, mac 5, that is not stored in any workbook, then you'll have to issue the commands to do the mac5 operations from your MATLAB code. And of course you can use ActiveX to switch the active workbook so that your operations can take place in whatever workbook you want.
This is by design and intended by Microsoft and does not indicate any error or problem with my code and demos. It's just the way things work.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!