Actxserver unable to locate Excel workbook

5 views (last 30 days)
I am having issues getting the ActiveX application to open an existing Excel doc for editing.
My current code looks like:
file_name = 'Excel_Book.xlsx';
xl = actxserver('Excel.Application');
xlb = xl.Workbooks.Open(file_name);
This returns the error:
Invoke Error, Dispatch Exception:
Source Microsoft Excel
Description: 'Excel_Book.xlsx' could not be found
I know that the file exists, as I can read it with
I have even changed the MATLAB directory to be seeing the folder with the Excel_Book file in it, and yet the ActiveX refuses to read the document.
Similar problems were encountered using:
xlb = xl.Workbooks.Item(file_name);
xlb = xl.get('Workbooks',file_name);

Accepted Answer

Walter Roberson
Walter Roberson on 28 Jul 2016
It would be safer to use fullfile() to create a fully-qualified file name to request to open.
Bob Thompson
Bob Thompson on 28 Jul 2016
[filename, filedir] = uigetfile();
That second field is exactly what I needed, thanks.

Sign in to comment.

More Answers (1)

Shameer Parmar
Shameer Parmar on 28 Jul 2016
Try replacing the line and check..
xlb = xl.Workbooks.Open(file_name);
xlb = xl.Workbooks.Open('fullpath\file_name along with the extension');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!