Running Excel VBA functions(macros) from MATLAB using a parfor loop
1 view (last 30 days)
Show older comments
I am trying to perform a particle swarm optimization (PSO) in which I require MATLAB to be interfaced with Excel VBA. Each particle is linked to an individual Excel Workbook. I have been able to successfully carry out a function call to Excel while using a for loop. However when I use a parfor loop, I get the following error: "Cannot run the macro 'Output'. The macro may not be available in this workbook or all macros may be disabled".
Below is a sample code:
Np = 3 % Number of particles
for i = 1:Np Excelpar(i) = actxserver('Excel.Application'); Workbook(i) = Excelpar(i).Workbooks.Open(workfile{i},1,true); % workfile{i} indicates the path of % the Excel workbook Excelpar(i).visible = false; Excelpar(i).DisplayAlerts = false; end
parfor k = 1:Np % I have no problems when this is a for loop c = zeros(1,6); c = Excelpar(k).Run('Output',x(k,1), x(k,4), Feed_B(k), x(k,5), x(k,2), x(k,3), P(k)); end
Any help provided is warmly appreciated Thanks
0 Comments
Answers (0)
See Also
Categories
Find more on Data Export to MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!