COMException on InvokeMember

K

-kve-

Hi,

I create an Excel chart in a Word document. I'm trying to change the chart
type at runtime (using late binding):

// Create the Word application and declare a document
Word2007.Application word = new Word2007.Application();
Word2007.Document doc = new Word2007.Document();

// Define an object to pass to the API for missing parameters
object missing = Type.Missing;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

word.Visible = true;

// Everything that goes to the interop must be an object
object fileName = string.Format(@"{0}\table.doc",
Path.GetDirectoryName(Application.ExecutablePath));

// Open the Word document.
object varFalse = false;
object varTrue = true; ;
// Create a new file based on our template
doc = word.Documents.Open(ref fileName, ref missing, ref varFalse, ref
missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref varTrue,
ref missing, ref missing, ref missing, ref missing);


//Insert a chart.
object oClassType = "Excel.Chart.8";
Word2007.Range wrdRng = doc.Bookmarks.get_Item(ref oEndOfDoc).Range;
InlineShape oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing);

object oChart = oShape.OLEFormat.Object;
object oChartApp = oChart.GetType().InvokeMember("Application",
BindingFlags.GetProperty,
null, oChart, null);

//Change the chart type to Line.
object[] Parameters = new Object[1];
Parameters[0] = 4; //xlLine = 4
oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty, null,
oChart, Parameters);


Here (on InvorkeMember) I get a COMException ("Unknown name. (Exception from
HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))")

My guess is that there is something wrong with the "ChartType" parameter...

I use Office 2007, but mu code should also work with Office 2003

Can anyone help me please?
 
K

-kve-

Found the problem:
I have installed an English Excel, but my regional settings are set to
another language...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top