Starting macro from c++
-
Hi, I am dealing with Excel Automation. I get most things working, but now I have a very strange behaviour: I created a big macro, which creates a pivot table from a normal table, and then makes a chart out of it. When I run the macro from the excel file, everything works! But, when I run the macro through a c++ program, it crashes. Here my C++ code: hr = CreateObject(OLESTR("Excel.Application"), &pdispApplication); V_VT(&v) = VT_BOOL; V_BOOL(&v) = TRUE; hr = Invoke(pdispApplication, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, OLESTR("Visible"), TEXT("v"), v); hr = Invoke(pdispApplication, DISPATCH_PROPERTYGET, &vRet, NULL, NULL, OLESTR("WorkBooks"), NULL); pdispWorkbook = V_DISPATCH(&vRet); V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(OLESTR("C:\\Dokumente und Einstellungen\\geh\\Desktop\\Excel Tests\\Test02.xls")); hr = Invoke(pdispWorkbook, DISPATCH_METHOD, &vRet, NULL, NULL, OLESTR("Open"), TEXT("v"), v); V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(OLESTR("Test02.xls!Chart")); hr = Invoke(pdispApplication, DISPATCH_METHOD, &vRet, NULL, NULL, OLESTR("Run"), TEXT("v"), v); What it does: It creates the pivot table, and creates a new chart. But when trying to set the XValue or Value from a new series, it says: "The XValue-Propertie cant be set" Here the code snippet from the macro: Sheets.Add Charts.Add ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _ "Linie - Säule auf zwei Achsen" ActiveChart.SetSourceData Source:=Sheets("Tabelle3").Range("A1") Set st = ActiveChart.SeriesCollection.NewSeries With st .Name = "=""Anz. KLEs am Platz""" .XValues = "=Tabelle2!R4C3:R4C57" .Values = Values End With As I said, if run it directly from the xls file, it works! And yes, the table "Tabelle2" is there, and opened. If I put a "stop" before it, so that I can trace it, it looks totally equal! Wheres my problem? EDIT: I just solved it by using .XValues = Worksheets("Tabelle2").Range("A4:BP4") But I still would like to know where my problem was! DKT -- modified at 11:05 Monday 29th August, 2005