0
votes

I have a macro written that copies a picture of a certain range and copies it into a chart object. The code works perfectly, but when I increase the size of the range I get run time 1004 error 'Application-defined or object-defined error'. i.e...I change U40 below to U50.

Does anyone see an issue I'm missing, that might be causing this error?

Sub RangePicSales()
With Worksheets("Dashboard").Range("F8:U40")
    .CopyPicture xlScreen, xlBitmap
    With ActiveSheet.ChartObjects.Add(.Left, .Top + .Height + 1, .Width, .Height).Chart
        .Paste
        With .Shapes(1)
            .Placement = xlMove
            .Left = -4
            .Top = -4
        End With
        .Export Filename:="RemovedFilePathForPost\WeeklySalesDashboard.png", Filtername:="PNG"
        .Parent.Delete
    End With
End With

End Sub

1

1 Answers

0
votes

Can't explain why but this works better - something to do with resizing the chart vs. trying to create it at the right size...

Sub Tester()
Dim rng, co As Object, cht As Chart

    Set rng = ActiveSheet.Range("A1:M1000")
    rng.CopyPicture appearance:=xlScreen, Format:=xlBitmap

    Set co = ActiveSheet.ChartObjects.Add(1, 1, 100, 100)
    With co
        .Width = rng.Width
        .Height = rng.Height
        .Chart.Paste
        .Chart.Export Filename:="C:\_Stuff\tester2.png", Filtername:="PNG"
        .Delete
    End With

End Sub

I was able to export a picture of A1:M1000