From: Roberto on
I've build a macro in excel which creates a histogram. I've tried it in excel and it works fine. Because I've to run that macro over multiple excel-files, I've created a m-code:

Excel=actxserver('Excel.Application');
set(Excel, 'Visible', 0);
winopen('E:\Macro.xls');
Excel.Run(['''', 'Macro.xls', '''!histogram']);
invoke(Excel, 'Quit');
clear Workbooks Excel;

And for any reason the macro doesn't work anymore... The macro holds on this line:
ActiveChart.SeriesCollection(1).XValues = "=Page2!R3C2:R3C46"
That line is needed to set the labels on the x-axis.

Anyone an idea why this macro works when I run it in excel and why it doesn't work when I run it from matlab??

If more information is required: let me know!
From: Rune Allnor on
On 31 Jul, 13:41, "Roberto " <ivogr...(a)hotmail.com> wrote:
> I've build a macro in excel which creates a histogram. I've tried it in excel and it works fine. Because I've to run that macro over multiple excel-files, I've created a m-code:
>
> Excel=actxserver('Excel.Application');
> set(Excel, 'Visible', 0);
> winopen('E:\Macro.xls');
> Excel.Run(['''', 'Macro.xls', '''!histogram']);
> invoke(Excel, 'Quit');
> clear Workbooks Excel;
>
> And for any reason the macro doesn't work anymore... The macro holds on this line:
> ActiveChart.SeriesCollection(1).XValues = "=Page2!R3C2:R3C46"
> That line is needed to set the labels on the x-axis.
>
> Anyone an idea why this macro works when I run it in excel and why it doesn't work when I run it from matlab??
>
> If more information is required: let me know!

What does "doesn't work" mean? As far as I can tell, Excel
is never visible, so you will not see anything on screen.
There is nothing in the above that saves the resulting
plot anywhere, so unless the plot is saved directly from
the macro itself, you will never see any results.

How do you access the results?

Rune
From: Roberto on
Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <551ff458-d46e-4dc8-8535-418f85d5b1b4(a)x21g2000yqa.googlegroups.com>...
> On 31 Jul, 13:41, "Roberto " <ivogr...(a)hotmail.com> wrote:
> > I've build a macro in excel which creates a histogram. I've tried it in excel and it works fine. Because I've to run that macro over multiple excel-files, I've created a m-code:
> >
> > Excel=actxserver('Excel.Application');
> > set(Excel, 'Visible', 0);
> > winopen('E:\Macro.xls');
> > Excel.Run(['''', 'Macro.xls', '''!histogram']);
> > invoke(Excel, 'Quit');
> > clear Workbooks Excel;
> >
> > And for any reason the macro doesn't work anymore... The macro holds on this line:
> > ActiveChart.SeriesCollection(1).XValues = "=Page2!R3C2:R3C46"
> > That line is needed to set the labels on the x-axis.
> >
> > Anyone an idea why this macro works when I run it in excel and why it doesn't work when I run it from matlab??
> >
> > If more information is required: let me know!
>
> What does "doesn't work" mean? As far as I can tell, Excel
> is never visible, so you will not see anything on screen.
> There is nothing in the above that saves the resulting
> plot anywhere, so unless the plot is saved directly from
> the macro itself, you will never see any results.
>
> How do you access the results?
>
> Rune
The macro saves the plot on the excel-file itself. So yes, I shouldn't actually see the results on screen. But during the execution of the matlab-code (and therefore also the macro) excel comes up with a pop up screen with an error. The error says that ActiveChart.SeriesCollection(1).XValues = "=Page2!R3C2:R3C46" could'n be executed.
So I know that there is a problem and I also know the line which doesn't work.
From: james bejon on
Hard to say exactly what's going wrong here. (I take it Page2 exists as a sheet and has valid data in the relevant cells). You might want to try it keeping the application visible just to see if that makes any difference. You might also want to try using specific Excel methods (like .Workbooks.Open rather than winopen) to see if this makes any difference. Also, might you have any 03/07 issues here? The reason I ask is because Excel 07 has a difference chart object model to Excel 03 (iirc).
From: Roberto on
"james bejon" <jamesbejon(a)yahoo.co.uk> wrote in message <i33695$iho$1(a)fred.mathworks.com>...
> Hard to say exactly what's going wrong here. (I take it Page2 exists as a sheet and has valid data in the relevant cells). You might want to try it keeping the application visible just to see if that makes any difference. You might also want to try using specific Excel methods (like .Workbooks.Open rather than winopen) to see if this makes any difference. Also, might you have any 03/07 issues here? The reason I ask is because Excel 07 has a difference chart object model to Excel 03 (iirc).

I'm using excel 2003 and making the application visible doesn't make any difference...
The strange thing is that when I run the macro in excel it works fine. But when I let the same macro run by matlab (see the m-code posted previously), it doesn't work. A pop up shows me the problem is the line which set the labels on the x-axis.

I've also run the same macro without that line by matlab and than it also works fine (but than the labels on the x-axis aren't set like I wanted). So I think it's clear that the problem doesn't have anything to do with excel, the m-code or the macro (except that line).

If you want to try it yourself, I've posted an excel-file (Macro.xls) right here:
http://www.mijnbestand.nl/Bestand-J7XFQXBS3TMP.xls
The macro contains one worksheet (Blad1) and the macro. If you run the macro from excel, you'll see that it works fine (a new worksheet will be created with some data and the histogram). But if you let the macro run by matlab with the following m-code, you'll see that it doesn't work.

Excel=actxserver('Excel.Application');
set(Excel, 'Visible', 0);
winopen('Macro.xls');
Excel.Run(['''', 'Macro.xls', '''!berekening_alle_runs']);
invoke(Excel, 'Quit');
clear Workbooks Excel;

Maybe this could help you to understand the problem or even better to fix it! :)