f



Closing an excel workbook through Matlab

Hi there,

I'm busy writing some code that opens an existing excel file through
Matlab, copies some information from Matlab into the excel file, runs
an excel macro, and finally saves and exits the excel file.

I've got everything to work, but the problem is I get a prompt from
excel telling me that the spreadsheet file exists and asking me if
I'd like to save over it. I'd like to automatically answer yes and
not have the dialog box appear. I've pasted my code below, does
anyone have any ideas?

The problem occurs when I execute the command wdata.save;

Thanks in advance,

Paul

% Writes a matrix to an excel spreadsheet and then runs a macro
%

% Open excel
e = actxserver('Excel.Application');

% Open an existing spreadsheet
wdata = e.Workbooks.Open('C:\Program
Files\MATLAB71\work\vba_test2.xls');

% Make the first sheet active.
eSheets = wdata.Sheets;
eSheet1 = eSheets.get('Item', 1);
eSheet1.Activate;

% Create a matrix
A = ceil(rand(3,3)*100);

% Copy the matrix into the first sheet of vba_test.xls
eActivesheetRange = e.Activesheet.get('Range', 'A1:C3');
eActivesheetRange.Value = A;

% Execute a macro
e.ExecuteExcel4Macro('!Example2()');

% Save the spreadsheet
wdata.Save;
wdata.Close;

% Quit Excel and delete the server.
e.Quit;
e.delete;
0
1/24/2006 12:52:34 PM
comp.soft-sys.matlab 211266 articles. 15 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
2860 Views

Similar Articles

[PageSpeed] 12

"Paul Jacot-Guillarmod" <paul_jacot@yahoo.removethis.co.uk> wrote in message 
news:ef26725.-1@webx.raydaftYaTP...
> Hi there,
>
> I'm busy writing some code that opens an existing excel file through
> Matlab, copies some information from Matlab into the excel file, runs
> an excel macro, and finally saves and exits the excel file.
>
> I've got everything to work, but the problem is I get a prompt from
> excel telling me that the spreadsheet file exists and asking me if
> I'd like to save over it. I'd like to automatically answer yes and
> not have the dialog box appear. I've pasted my code below, does
> anyone have any ideas?

I think what you'll need is under the SaveAs method of this MSDN page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrgrfexcelapplicationobjectmethods.asp

-- 
Steve Lord
slord@mathworks.com 


0
slord (13687)
1/24/2006 5:55:32 PM
Reply: