Problem with MATLAB talking to Window7
1 view (last 30 days)
Show older comments
My following code that works perfectly in WindowXP no longer work on Window7. Can you suggest changes?
fileName = 'K:\Folder\ExceFileName.xls';
objExcel = actxserver('Excel.Application');
exlWkbk = objExcel.Workbooks;
exlFile = exlWkbk.Open(fileName); %Opens filename
exlSheet = exlFile.Sheets.Item('Data'); %Data is name of Excel sheet
I get the following message when running the last line:
No appropriate method, property, or field Sheets for class
Interface.000208DA_0000_0000_C000_000000000046.
Thanks, Luiz
7 Comments
Guillaume
on 21 Nov 2014
Edited: Guillaume
on 21 Nov 2014
It's probably the same error that you get in matlab, so at least you know it's nothing to do with matlab.
In matlab, once you've got exlFile, have a look at its properties with
inspect(exlFile) %may take a while to populate
Maybe it will shed some clues as to what's going own.
Otherwise, if you can, attach your excel file. Maybe there's something peculiar about it.
The error you get is very unusual. Your code is correct, and if the sheet requested did not exist you'd get a completely different error message.
Answers (1)
Guillaume
on 21 Nov 2014
The VBScript error code is more helpful than matlab's one. There's not much information on this error code but a bit of googling would seem to indicate that there's a macro in your workbook that's interfering with the loading of the sheet. Possibly, the macro executes when the sheet is opened or possibly the macro fails to execute.
Does
objExcel.EnableEvents = false; %prevent macros from executing
before loading the workbook, solve the problem?
2 Comments
Guillaume
on 24 Nov 2014
I'm not really familiar with excel add-ins, I'm afraid.
It may be possible to disable the problematic add-in using the addin Installed property. You can enumerate the add-ins through the addIns collection of the Application object:
for idx = 1:objExcel.AddIns.Count
fprintf('Add-in %d is %s\n', idx, objExcel.AddIns.Item(idx).Name);
end
And then
objExcel.AddIns.Item(???).Installed = false; %replace ??? by appropriate number
That's all according to MSDN. No idea if it works.
See Also
Categories
Find more on Data Import from 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!