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.
 
Hi :)

I am able to replicate the error with this code:

Code:
Sub showgraph()

Dim myWB As Excel.Workbook
Dim mychart As ChartObject
Dim spsheetfilename$

On Error GoTo Handler

spsheetfilename$ = "C:\Work\360s\sample-files\new\1 graph.xlsx"
Set myWB = GetObject(spsheetfilename$)

'Correct number of charts below
numberofcharts% = myWB.Sheets("Graphs").ChartObjects.Count
Set mychart = myWB.Sheets("Graphs").ChartObjects(1)
With mychart.Chart
    .CopyPicture Appearance:=xlScreen, Format:=xlPicture
End With

Handler:
    MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical

End Sub

I am running the above code via a .docm word file (references: http://i.imgur.com/jDsKPor.png) and it is opening '1 graph.xlsx' (http://i.imgur.com/nLxRJdR.png).

Macro file on dropbox: https://www.dropbox.com/s/flzfgev2o9v5c5b/1 graph macro.docm?dl=0
Excel file on dropbox: https://www.dropbox.com/s/yer18dfl7anm8d5/1 graph.xlsx?dl=0

Thanks again
Seb
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Seb,

Thanks for uploading some sample files, it will make it easier to troubleshoot! I'm on my lunch break at the moment, but will take a look at it this evening once I'm back from work.

Thanks
Caleeco
 
Upvote 0
Hi Seb,

Sorry I didn't get a change to look at this yesterday. Currently making some updates to my website, which is a black-hole for time! I will endeavour to take a look this evening.

Cheers
Caleeco
 
Upvote 0
I believe I solved the problem (related to how I was opening the workbook, which is strange considering text was correctly extracted from the wb, but graphs were not). I'll post a snippet later for anyone browsing the topic.

Thanks again for all your help :)
 
Upvote 0
I believe I solved the problem (related to how I was opening the workbook, which is strange considering text was correctly extracted from the wb, but graphs were not). I'll post a snippet later for anyone browsing the topic.

Thanks again for all your help :)

Ah nice! Glad you got it sorted, thanks for letting me know

Yeah will be worthwhile posting working code for anyone facing a similar problem in the future :)

Caleeco
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

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