1004 the specified dimension is not valid for the current chart type

sebmorris

New Member
Joined
Apr 3, 2017
Messages
10
Hi guys

I've been stuck with this problem for a while now and was hoping one of you could help out :).

The problem code is shown below and is being run from a word document which reads an excel file (myWB - opened with a GetObject call).

Code:
With myWB.Sheets("Graphs").ChartObjects(chartreq%).Chart
        'Name of the chart is correct
        temp$ = .Name
        .ChartType = Excel.XlChartType.xlColumnClustered

        'error occurs on the line below (1004 the specified dimension is not valid for the current chart type)
        .CopyPicture Appearance:=xlScreen, Size:=xlPrinter, Format:=xlPicture
        
        'pasting chart etc...
    End With

The graph is correct in the excel document and the type is the same as the .ChartType i set.

Any help would be greatly appreciated, no idea where to go from here and ive tried many different approaches.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Seb,

It would help if you could tell us which line produces the error? (Should be highlighted yellow when you run the code)

Caleeco
 
Upvote 0
I specified the line causing the error in my code block (with a comment).

Code:
'error occurs on the line below (1004 the specified dimension is not valid for the current chart type)
.CopyPicture Appearance:=xlScreen, Size:=xlPrinter, Format:=xlPicture
 
Upvote 0
Ah ok sorry I didnt spot that! From what i've looked up, your syntax to apply that particular method may be incorrect. For test purposes try this and see if it runs:
Code:
With myWB.Sheets("Graphs").ChartObjects(chartreq%).Chart
        'Name of the chart is correct
        temp$ = .Name
        .ChartType = Excel.XlChartType.xlColumnClustered
End With
myWB.Sheets("Graphs").ChartObjects(chartreq%).CopyPicture Appearance:=xlScreen, Size:=xlPrinter, Format:=xlPicture

Caleeco
 
Upvote 0
Hi Seb,

The syntax below works on my test sheet. Change SHEET and ObjectNames accordingly:

Code:
Sub ChartCopy()
Dim mychart As ChartObject


Set mychart = ThisWorkbook.Sheets("Sheet1").ChartObjects("Chart 1")
With mychart.Chart
   .CopyPicture Appearance:=xlScreen, Format:=xlPicture
End With
End Sub


Caleeco
 
Upvote 0
Thanks again Caleeco

Code:
Dim mychart As ChartObject
Set mychart = myWB.Sheets("Graphs").ChartObjects(1)
With mychart.Chart
    .CopyPicture Appearance:=xlScreen, Format:=xlPicture
End With

Your code (^^) displays the same error, does that imply there is an issue with the chart (the chart is shown in the screenshot i sent)?
 
Upvote 0
Hmm that's strange. Are you able to upload your spreadsheet?

It would suggest there is something wrong with either the chart name or chartobject definition. You could try activating the workbook/worksheet before trying to use the CopyPicture method.

What has your variable 'myWB' been set as?

Caleeco
 
Upvote 0

Forum statistics

Threads
1,216,180
Messages
6,129,340
Members
449,505
Latest member
Alan the procrastinator

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top