Results 1 to 3 of 3

Thread: Excel VBA error: Method Add of ChartObjects failed

  1. #1
    Join Date
    Nov 2010
    Posts
    3

    Excel VBA error: Method Add of ChartObjects failed

    I'm using Excel 2007 trying to create a macro to draw a chart. Using Record Macro doesn't work. So have tried many attempts at writing one, now even the suggestion in Excel Help gives an error.
    Method 'Add' of 'ChartObjects' failed.

    Here's the code:

    Dim ch As ChartObject
    Set ch = Worksheets("Sheet1").ChartObjects.Add(100, 30, 400, 250)
    ch.Chart.ChartWizard Source:=Worksheets("Sheet1").Range("c1:f20"), _
    Gallery:=xlLine, Title:="New Chart"

    From similar links I've made sure that Sheet protection is off and there is no printer enabled.
    Hope someone can help solve this.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,010

    Re: Excel VBA error: Method Add of ChartObjects failed

    It appears to me as an office automation issue try to take help from the codes which are given below:

    Code:
                object missing = Type.Missing;
                Excel.Application myApp= new Microsoft.Office.Interop.Excel.Application();
                myApp.Visible = true;
                myApp.Workbooks.Add(missing);
                Excel.Worksheet ws = (Excel.Worksheet)myApp.ActiveSheet;
                Excel.ChartObjects chartobjects = (Excel.ChartObjects)ws.ChartObjects(missing);
                Excel.ChartObject chartobject = (Excel.ChartObject)chartobjects.Add(10 /*Left*/, 100 /*Top*/, 600 /*Width*/, 400 /*Height*/);
                Excel._Chart chart = (Excel._Chart)chartobject.Chart;

  3. #3
    Join Date
    Nov 2010
    Posts
    3

    Re: Excel VBA error: Method Add of ChartObjects failed

    Hi Kelfro,
    The code I assume is external to the application, something that calls Excel. Not quite sure where to embed it. What I was looking for was some solution to the problem of creating a chart within a macro. A VBA solution. I can accept that the problem maybe a Microsoft Office problem associated with Excel, but not sure where to go from there.
    I tried assembling the code into the macro, but as it isn't VBA code most of the lines errored and trying to fix those errors just made more errors and the code ended up not resembling what you had submitted. For instance
    VBA doesn't understand Type missing --> it expects an expression etc ending with an End Type.
    Any further thoughts will be gratefully received.
    Thanks,
    T_J.

Similar Threads

  1. Replies: 1
    Last Post: 14-03-2012, 01:08 PM
  2. Is there a way to setup Bisection method in Microsoft Excel
    By Sreedharna in forum MS Office Support
    Replies: 2
    Last Post: 16-02-2012, 06:56 PM
  3. Replies: 5
    Last Post: 15-12-2010, 06:18 PM
  4. Run time error:'1004': Method 'Range' of object '_Global' failed
    By 2muchreality in forum Software Development
    Replies: 2
    Last Post: 11-10-2008, 02:46 PM
  5. Replies: 1
    Last Post: 15-02-2007, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •