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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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