Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA图表对象-1004错误_Excel_Vba - Fatal编程技术网

Excel VBA图表对象-1004错误

Excel VBA图表对象-1004错误,excel,vba,Excel,Vba,我编写了一个宏,它将某个范围的图片复制到图表对象中。代码工作得很好,但是当我增加范围的大小时,我得到运行时1004错误“应用程序定义的或对象定义的错误”。i、 我把下面的U40改成U50 是否有人看到我遗漏的可能导致此错误的问题 Sub RangePicSales() With Worksheets("Dashboard").Range("F8:U40") .CopyPicture xlScreen, xlBitmap With ActiveSheet.ChartObjects.

我编写了一个宏,它将某个范围的图片复制到图表对象中。代码工作得很好,但是当我增加范围的大小时,我得到运行时1004错误“应用程序定义的或对象定义的错误”。i、 我把下面的U40改成U50

是否有人看到我遗漏的可能导致此错误的问题

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无法解释为什么,但它的效果更好-这与调整图表的大小有关,而不是尝试以正确的大小创建图表

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
我能够导出A1:M1000的图片