MATLAB: Xlswrite1, Object returned error code: 0x800A03EC at line 142

excelxlswrite1

I am first time using xlswrite1 and tried to not use xlswrite in the for loop, I want to enter the data from a structure, which contains 27 fields, each field has Mx1 Data,
I first tried with xlswrite:
for VariableNum = 1:length(fieldnames(Data))
xlswrite(FileAddress,Data.(ColumnName{VariableNum}),1,[Column{VariableNum} num2str(4)]);
end
Although it took me half minute to complete. the above line worked perfectly fine. and then i tried with the xlswrite1, didn't change any input except adding a few lines to open excel,
Excel = actxserver ('Excel.Application');
File=FileAddress;
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
end
for VariableNum = 1:length(fieldnames(Data))
xlswrite1(FileAddress,Data.(ColumnName{VariableNum}),1,[Column{VariableNum} num2str(4)]);
end
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
Excel.delete
clear Excel
I uses this xlswrite1 in my custom function, which is used in a GUI function. I also changed the second line in xlswrite1 from
Excel=evalin('base','Excel');
to
Excel=evalin('caller','Excel');
as suggested.
for some reason this gave me error indicated in the title.

Best Answer

Why did you do this to close your workbook:
ExcelWorkbook.Close(false);
I would think that xlswrite1() would expect that Excel has the workbook open. If you don't have an active workbook open, where will it write to? You just have Excel open with no workbook, and no worksheet in the workbook (because the workbook itself is not there). Try getting rid of the .Close call and see if that works.
Related Question