Why using actxserver will turn my file to read-only
18 views (last 30 days)
Read-only error been showed while I was trying to movefile, but the new directories is either my Downloads folder or my Desktop folder.
Here is what I did:
I first loaded the Excel file that I'd like to modify, and then turn on the actxserver('Excel.Application'), and then apply action for that pre-loaded excel file.
But I got error while I was trying to movefile(oldfilePath, newfilePath): "Use the 'f' option to override". This error does not make sense since neither the new location I have selected shall not be read-only space,nor there is no duplicate file existed in that directory.
I think somehow there is a delay happened between Excel and MATLAB, in another word, I feel the modifies Excel file was not saved successfully.
Does anyone has ever met this problem before?
Guillaume on 2 May 2019
Edited: Guillaume on 2 May 2019
cRowNames = templateExcel.Properties.RowNames;
would imply that templateExcel is a matlab table. Yet on the previous line, you have:
which, if templateExcel is indeed a table is meaningless.
Later on in your code, you use the variable targetTable which is undefined. So this will also cause an error. I suspect that that targetTable is meant to be templateExcel but it's hard to know since the code is not commented.
Note that it's much easier to write a table to an excel file directly with writetable rather than converting to a cell array and then using xlswrite.
Later on you use the variable sExcelClearRange which is also undefined. In any case, relying on the ActiveSheet being the correct sheet after you've just opened the file in excel is very iffy. You may very well clear a different sheet than intended.
is not valid. I suspect you meant
which could be combined with the previous Workbook.Save line to just:
workbook.Close(true); %true to save and close the file all at once.