Note that there are some explanatory texts on larger screens.

plurals
  1. POError setting PlotArea.Width in Excel, VBA (Excel 2010)
    primarykey
    data
    text
    <p>I am experiencing an error in a subroutine attempting to set the plotarea.width property of a chart.</p> <p><img src="https://i.stack.imgur.com/nk47Y.jpg" alt="enter image description here"></p> <p>The other dimensions also cause this error if I comment out the preceding line(s). There is no ActiveChart, no selection, etc. The specific error message is this: "-2147467259 (80004005) Method 'Width' of object 'PlotArea' failed"</p> <p>This is stumping me for several reasons:</p> <ul> <li>In debug mode, F8 to step through the code the error does NOT occur. </li> <li>AFAIK "width" is not a "method" but a "property" of the chart's plotarea, so even the error message is rather ambiguous.</li> </ul> <p>Any thoughts? Here's as much code as I can share, the ChartSizeMedium subroutine in its entirety, and a dummy snippet to show you how I am establishing the chart and passing it to that sub which sets the size &amp; some other properties prior to passing to another function which adds the series data to the chart.</p> <pre><code> Option Explicit Private Sub EstablishChartObject() Dim cObj as ChartObject Set cObj = ActiveSheet.ChartObjects.Add(Left:=30, Top:30, Width:=740, Height:=300) ChartSizeMedium cObj.Chart, "Integer", "Example Chart Title" End Sub Private Sub ChartSizeMedium(cht As Chart, NumType As String, Optional chtTitle As String) 'Subroutine to make a consistent size chart Dim s As Long With cht 'Add a chart title if one exists. If Len(chtTitle) &gt; 0 Then .HasTitle = True .chartTitle.Characters.Text = chtTitle End If 'Create the default chart Legend .HasLegend = True With .Legend .Position = xlTop .Font.Size = 11 .Font.Bold = True End With 'Format the axes .Axes(xlValue).MajorGridlines.Format.Line.Visible = msoFalse .Axes(xlValue).MinorGridlines.Format.Line.Visible = msoFalse 'Format the size of the chart With .Parent .Width = 740 .Height = 396 End With With .PlotArea .Width = 640 '&lt;---- THIS LINE TRIGGERS THE ERROR .Height = 280 .Left = 30 .Top = 30 End With End With 'Some charts start with more than one series container, so make sure they're gone: With cht Do Until .SeriesCollection.Count = 0 s = .SeriesCollection.Count .SeriesCollection(s).Delete Loop End With End Sub </code></pre> <p><strong>UPDATE Dec 12, 2012</strong></p> <p>I remove all non-problematic code and use only the PlotArea with block, in the same routine, I have also tried setting the chart type (several values) and as shown in this example, manually adding one series of data prior to attempting to set the PlotArea dimensions, but the error persists:</p> <pre><code>Option Explicit Private Sub EstablishChartObject2() Dim cObj As ChartObject Dim sh As Worksheet Set sh = ActiveSheet Dim srs As Series Set cObj = sh.ChartObjects.Add(Left:=30, Top:=30, Width:=740, Height:=300) Set srs = cObj.Chart.SeriesCollection.NewSeries srs.Values = "={1,3,5,7,4}" cObj.Chart.ChartType = 57 With cObj.Chart.PlotArea .Width = 100 '&lt;---- THIS LINE TRIGGERS THE ERROR .Height = 280 .Left = 30 .Top = 30 End With End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload