Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Excel VBA error: Method Add of ChartObjects failed

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2010
Member
 
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.

Reply With Quote
  #2  
Old 20-11-2010
Member
 
Join Date: Apr 2008
Posts: 1,999
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;
Reply With Quote
  #3  
Old 22-11-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Excel VBA error: Method Add of ChartObjects failed"
Thread Thread Starter Forum Replies Last Post
Excel VBA Run-time error '1004' Paste method of Worksheet class failed PatrickW Windows Software 1 14-03-2012 01:08 PM
Is there a way to setup Bisection method in Microsoft Excel Sreedharna MS Office Support 2 16-02-2012 06:56 PM
During bootup I get this error message Error invoking method: main (java.lang.string) Karsten M Windows Software 5 15-12-2010 06:18 PM
Run time error:'1004': Method 'Range' of object '_Global' failed 2muchreality Software Development 2 11-10-2008 02:46 PM
DsBindWithSpnEx() failed with error 1722 & [FSMO_HOLDER] LDAP search failed with error 58 Nino_1 Windows Server Help 1 15-02-2007 05:27 PM


All times are GMT +5.5. The time now is 06:41 AM.