Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Excel ActiveX SaveAs interface

32 views
Skip to first unread message

Brian

unread,
Mar 13, 2009, 2:52:01 PM3/13/09
to
I'm trying to write a program in matlab that will have excel create a CSV file based on an existing spreadsheet, but I'm having trouble coaxing the activex interface into saving an xls file as a csv file. Here's what I've done so far:

I recorded a macro in excel to see how this might be done, and found that it requires the following:

ActiveWorkbook.SaveAs Filename:= _
"myfile.csv" _
, FileFormat:=xlCSV, CreateBackup:=False

I tried using the 'SaveAs' method of excel's worksheet class through activex. I've tried the following syntax with no luck:
invoke(exsheet,'SaveAs','myfile.csv') %Writes a binary excel file to the csv filename
invoke(exsheet,'SaveAs','myfile.csv', 'xlCSV') %Throws an error b/c too many inputs
invoke(exsheet,'SaveAs',{'myfile.csv', 'xlCSV'}) %writes an xls file to myfile.csv, and writes xls to xlCSV as well
set(exsheet,'FileFormat','xlCSV')

Nomad

unread,
May 14, 2009, 5:18:01 PM5/14/09
to
Brian,

Here is how I am doing this operation:

Excel = actxserver('Excel.Application');
Excel.Workbooks.Open('myfile.xls');
Excel.ActiveWorkbook.SaveAs('myfile.csv', 6);

where 6 is the Excel constant conformable to xlCSV.

Hope it helps.

"Brian " <skinny.leg...@gmail.com> wrote in message <gpea0h$okb$1...@fred.mathworks.com>...

Brian

unread,
May 15, 2009, 9:44:02 AM5/15/09
to
Thanks so much - that worked perfectly!

"Nomad " <no...@nomad.com> wrote in message <gui1q9$33u$1...@fred.mathworks.com>...


> Brian,
>
> Here is how I am doing this operation:
>
> Excel = actxserver('Excel.Application');
> Excel.Workbooks.Open('myfile.xls');
> Excel.ActiveWorkbook.SaveAs('myfile.csv', 6);
>
> where 6 is the Excel constant conformable to xlCSV.
>
> Hope it helps.
>
>
>
> "Brian " <skinny.leg...@gmail.com> wrote in message <gpea0h$okb$1...@fred.mathworks.com>...
> > I'm trying to write a program in matlab that will have excel create a CSV file based on an existing spreadsheet, but I'm having trouble coaxing the activex interface into saving an xls file as a csv file. Here's what I've done so far:
> >
> > I recorded a macro in excel to see how this might be done, and found that it requires the following:
> >
> > ActiveWorkbook.SaveAs Filename:= _
> > "myfile.csv" _

> > , FileFormat:=xlCSV, CreateBackup:?lse

0 new messages