1

The following MATLAB code runs the macro test saved as a module in the excel file test.xlsx:

filename = 'test.xlsx';
Excel = actxserver('Excel.Application');
workbook = Excel.Workbooks.Open(filename);
Excel.Application.Run("test");

Is there a way to run the same macro test, when it is saved in an external Basic Macro file, functions.bas, or as a text file, or as a string in memory, without turning the office file into a macro enable document?

Function test()
    MsgBox "Hello World"   
End Function
Community
  • 1
  • 1
Brethlosze
  • 1,533
  • 1
  • 22
  • 41
  • 1
    here is a similar question ... https://stackoverflow.com/questions/3183286/is-it-possible-to-run-a-macro-in-excel-from-external-command – jsotola Aug 15 '17 at 22:47
  • 1
    No, not without importing the bas file into Excel. There's no need for that though: the code doesn't have to be part of a document to be able top operate on that document: you can place the code inside an add-in or just an Excel file, and call it from there. – Tim Williams Aug 15 '17 at 22:49
  • @jsotola Note that i am already doing that. The question is about we can take the macro from a 'bas', or a text file, or a string in memory. But as pointed by TimWilliams storing it in a empty 'xls' wouldn be so terrible. – Brethlosze Aug 16 '17 at 00:28

0 Answers0