, VBA, (*.txt *.bas), , , VBA, :
DataFileName = 'D:\Test\DataFile.xlsm';
CodeFileName = 'D:\Test\CodeFile.txt';
Excel = actxserver('Excel.Application');
Workbooks = Excel.Workbooks;
Workbook=Workbooks.Open(DataFileName);
% Make Excel visible (Optional)
Excel.visible = 1;
%% Import the code
Import(Workbook.VBProject.VBComponents,CodeFileName);
%% Save
Excel.Application.DisplayAlerts = 0; %Avoid overwrite warning
SaveAs(Workbook,DataFileName);
Excel.Application.DisplayAlerts = 1;
%% Close Excel
Quit(Excel);
delete(Excel);
CodeFile.txt
:
Attribute VB_Name = "ModuleName"
Option Explicit
Sub SomeMacro()
Msgbox "From MATLAB, with love..."
End Sub
Attribute VB_Name = ...
. Option Explicit
, .