title: VBA Runtime Error 1004 on Set chartObject = myWS.Chartobjects.Add(0,0,100,100)
body: <p>I came across a problem in my VBA code. What I am trying to do is create a chartObject, add a chart to my worksheet and paste an image into it.</p>
  
  <p>My Code so far is as follows:</p>
  
  <pre><code>Function RangeToImage(sheetName As String, rangeToBeExported As String)
  
      Dim exportRange As Range
      Dim fName As String: fName = sheetName &amp; getConstNameForRange(rangeToBeExported)
      Dim cObject As ChartObject 'ChartObject
      Dim myChart As Chart
      Dim myWB As Workbook, myWS As Worksheet
  
      Set myWB = Application.ActiveWorkbook
      Set myWS = myWB.Worksheets(sheetName)
  
      myWS.Activate
      ActiveWindow.DisplayGridlines = False
  
      Call goToThisRange(myWS.Cells(1, 1))
  
      Set exportRange = Worksheets(sheetName).Range(rangeToBeExported)
      ActiveWindow.DisplayGridlines = False
      exportRange.CopyPicture Appearance:=xlScreen, Format:=xlPicture
  
      Set cObject = myWS.ChartObjects.Add(0, 0, 100, 100)
      cObject.Width = exportRange.Width
      cObject.Height = exportRange.Height
      cObject.Activate
  
      Set myChart = cObject.Chart
      myChart.Paste
      myChart.Export getSpeicherort(fName) &amp; IMAGEFORMATEXT, IMAGEFORMAT
      myChart.Parent.Delete
  
  End Function
  </code></pre>
  
  <p>However, the line</p>
  
  <pre><code>Set cObject = myWS.ChartObjects.Add(0, 0, 100, 100)
  </code></pre>
  
  <p>throws</p>
  
  <blockquote>
    <p>Runtime Error 1004: Application-defined or Object-defined error</p>
  </blockquote>
  
  <p>I'm completely lost with this one, is there anything I am missing or misunderstanding here?</p>
  
  <p>Any help is greatly appreciated!</p>