Problem with MATLAB talking to Window7

1 view (last 30 days)
Luiz
Luiz on 21 Nov 2014
Commented: Guillaume on 24 Nov 2014
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
Luiz
Luiz on 21 Nov 2014
Indeed, there was a mistake there.
Now message is:
Line:5 Char:1 Error: Unknown runtime error: 'exlFile.Sheets' Code: 800A9C64 Source: Microsoft VBScript runtime error
Guillaume
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.

Sign in to comment.

Answers (1)

Guillaume
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
Luiz
Luiz on 24 Nov 2014
Hi Guillaume,
objExcel.EnableEvents = false; %prevent macros from executing
does not solve the problem.
The peculiarity of this sheet is that it contains some excel-addin of data vendors on it (e.g. Datastream). So, it seems that when the sheet opens, because the Excel sheet sometimes opens without correcting loading such add-ins, some of the add-in code goes into debug mode. The code you sent has the intention to prevent that (by not allowing macros to run) but, unfortunately, it is not working in this case, where i get a VBA pop saying "Compile error: can't find project or library".
Is there other objExcel "disabling" code that is power powerful than this?
Best, Luiz
Guillaume
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.

Sign in to comment.

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!