Options

Excel Automation

ta5ta5 Member Posts: 1,164
Hi

I have 2 problems with the ffw Code.
1): How the graph is inserted in Sheet "Table Sheet", not in sheet "Graph Sheet". The Location-Method seems not to work this way...
I also tried to insert more sheets, the graph is always placed on the last inserted sheet.

2): Its not possible to use the .hasTitle-property (see deactivated code; if activated a runtime-error occurs).


Any tips?

Thank you in advance.

H



CREATE(xlApp,FALSE);

xlBook := xlApp.Workbooks.Add(-4167);

xlSheet2:= xlApp.ActiveSheet;
xlSheet2.Name := 'Graph Sheet';

xlSheet1 := xlBook.Sheets.Add;
xlSheet1.Name := 'Table Sheet';

xlSheet1.Range('A3').Value := 'Item 1';
xlSheet1.Range('A4').Value := 'Item 2';
xlSheet1.Range('A5').Value := 'Item 3';
xlSheet1.Range('A6').Value := 'Item 4';

xlSheet1.Range('B2').Value := 'Budget 2004';
xlSheet1.Range('B3').Value := 150;
xlSheet1.Range('B4').Value := 140;
xlSheet1.Range('B5').Value := 100;
xlSheet1.Range('B6').Value := 200;

xlSheet1.Range('C2').Value := 'Budget 2003';
xlSheet1.Range('C3').Value := 20;
xlSheet1.Range('C4').Value := 200;
xlSheet1.Range('C5').Value := 30;
xlSheet1.Range('C6').Value := 90;

xlSheet1.Range('D2').Value := 'Budget 2002';
xlSheet1.Range('D3').Value := 300;
xlSheet1.Range('D4').Value := 400;
xlSheet1.Range('D5').Value := 500;
xlSheet1.Range('D6').Value := 100;

xlRange := xlSheet1.Range('A2:D6');
xlChart := xlBook.Charts.Add;

xlChart.ChartType := 51; //Column
xlChart.SetSourceData(xlRange,2);
xlChart.Location(2,'Graph Sheet');
//xlChart.HasTitle(TRUE);

xlApp.Visible := TRUE;

Comments

  • Options
    FPulsfortFPulsfort Member Posts: 43
    Have you tried a xlsheet1.activate; after inserting this new sheet?

    Greetings,
    Frank
  • Options
    ta5ta5 Member Posts: 1,164
    Hi Frank

    Thanks for your answer. xlsheet1.activate did not work, but I've found a workaround for both now:

    1) Add the Data Sheet, then create the graph on a separate sheet, add a temporary sheet, move sheet to position 1, delete temporary sheet.

    2) This works
    xlBook.ActiveChart.HasTitle := TRUE;


    Regards
    H
Sign In or Register to comment.