Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Starting macro from c++

Starting macro from c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++testingdebuggingtoolshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kreatief
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups