C# : Chart.SetSourceData -> Exception

HeinrichMREx

New Member
Joined
Dec 9, 2012
Messages
7
Hallo there,

I would appreciate help on two questions :

1) what could be the reason for this line to throw an exception :

Code:
range = worksheet.get_Range("A3", "B4");
myChart.SetSourceData(range.ToString(), PowerPoint.XlRowCol.xlColumns);
Exception Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

I also tried

If I do it this way:

Code:
myChart.SetSourceData(range, Excel.XlRowCol.xlColumns);

I get compile errors:

1> error CS1502: The best overloaded method match for 'Microsoft.Office.Interop.PowerPoint.Chart.SetSourceData(string, object)' has some invalid arguments
1> error CS1503: Argument 1: cannot convert from 'Microsoft.Office.Interop.Excel.Range' to 'string'


2)
) Do you known of some methods, which allow the selection of Excel Datasheets areas, so that it looks like this(with the color lines and dotes on the corner of the selections) ? :

Excel_Markup.jpg
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
1. The SetSourceData method is expecting the address of the range, not its values.
2. If you select a chart, Excel automatically selects the data cells-that functionality is not directly exposed (at least not in VBA, so I doubt it's part of the PIAs)
 
Upvote 0
Thanks for replying.

1. The SetSourceData method is expecting the address of the range, not its values.
I always thought that "A3","D5" the address of the range is, not the values ...

2. If you select a chart, Excel automatically selects the data cells-that functionality is not directly exposed (at least not in VBA, so I doubt it's part of the PIAs)
How can I make sure it is part / not part of the PIA ? Do you have any reference ?

Best,
 
Upvote 0
"A3:D5" is the address of the range but that is not what you are passing to setsourcedata. If you use range.tostring you convert its values to strings and if you just pass range you are passing a range object. Note: this is PowerPoint interop code and not Excel.

Check MSDN for the object model, or use the object browser in Visual Studio: Chart.SetSourceData Method (Microsoft.Office.Interop.PowerPoint) for example.
 
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top