Hi everyone,
The question relates to setting up a .xla function to be used with Excel, compiled using the MATLAB Library Compiler. The knowledge I have so far is from Dr. Moritz Ernst post here . I would like to extend the capabilities shown in this example to populate a series of cells.
Let's imagine an example where user calls the function myACTXFunction from cell 'C1', with inputs 'A1 and 'B1'. Using the inputs myACTXFunction calculates 100 datapoints using LINSPACE, which should be populated in cells 'C1:C100'.
My knowledge in VBA syntax is poor, so I started experimenting with 'ACTXSERVER', where I managed to populate the values to a different workbook created new, every time the function is called.
Please see the code below that I compiled using Library Compiler to a .xla file.
function myACTXFunction(x)
dataSeries = (linspace(x(1,1),x(1,2),100))';
hServer = actxserver('excel.application');
eWs = hServer.Workbooks;
eW = eWs.Add;
eS = eW.ActiveSheet;
hServer.Visible = 1;
currentCellAddress = hServer.Selection.AddressLocal;
currentCellAddress_split = strsplit(currentCellAddress,'$');
letterID = currentCellAddress_split{2};
rowID = currentCellAddress_split{3};
targetCellAddressString = [letterID rowID ':' letterID num2str(100)];
hServer.ActiveSheet.Range(targetCellAddressString).Cells.Value =dataSeries;
end
My questions are:
- Is there a non - ACTXSERVER method to do what I need?
- Reading the information here, it looks like VBA does provide a means to locate the Address of the cell from which the function is called. Is there a way to use this within the MATLAB function?
Any thoughts on the matter would be most welcome. Thanks in advance