Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:34:01+00:00 2026-06-16T02:34:01+00:00

I am experiencing an error in a subroutine attempting to set the plotarea.width property

  • 0

I am experiencing an error in a subroutine attempting to set the plotarea.width property of a chart.

enter image description here

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”

This is stumping me for several reasons:

  • In debug mode, F8 to step through the code the error does NOT occur.
  • AFAIK “width” is not a “method” but a “property” of the chart’s plotarea, so even the error message is rather ambiguous.

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 & some other properties prior to passing to another function which adds the series data to the chart.

    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) > 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    '<---- 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

UPDATE Dec 12, 2012

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:

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   '<---- THIS LINE TRIGGERS THE ERROR
        .Height = 280
        .Left = 30
        .Top = 30
    End With

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:34:02+00:00Added an answer on June 16, 2026 at 2:34 am

    Two solutions that seem to be working, neither is really as “elegant” as I’d prefer (I was hoping there would be a way to do this with selecting the chart or any part of it).

    Option 1 – Select the plot area and then deselect it. This seems to be the most reliable/efficient solution.

    With .PlotArea
        Application.ScreenUpdating = False
       .Select
        With Selection
            .Width = paWidth
            .Height = paHeight
            .Left = paLeft
            .Top = paTop
            ActiveSheet.Range("A1").Activate
        End With
        Application.ScreenUpdating = True
    End With
    

    Option 2 – disable error-handling in loop (this followed from Doug’s link). This doesn’t seem to be a very reliable or efficient method, and although it seems to work, I know that within that loop it is failing once on each of the properties before it successfully sets them on a subsequent pass.

    With .PlotArea
        For pLoop = 1 To 5
            On Error Resume Next
            .Width = paWidth
            .Height = paHeight
            .Left = paLeft
            .Top = paTop
            On Error GoTo 0
        Next
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing this error... variable 'paymentLine' of type 'Xrm.sb_directdebitpaymentline' referenced from scope '', but
We are experiencing the same error as this StackOverflow Q ... System.Data.SqlClient.SqlException (0x80131904): A
I'm experiencing this error in Django 1.2 admin. Scenario: I have two applications, say
For some reason I'm experiencing the following Maven error, this was working before so
I do not know why I am experiencing this error. Actually content place holders
I am experiencing a fatal error while using artisan on the (fantastic) Laravel PHP
I am experiencing an unusual error using ItemizedOverlay in Android. I am creating a
I'm experiencing a weird error with the visual studio 11 beta WPF designer (i.e.
I am suddenly experiencing an intermittent error using the Google Checkout ASP.NET control GCheckout.
for some reason I'm experiencing the Operational Error with can't rollback message when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.