gpt4 book ai didi

excel - 指定形状宽度会生成错误 : The specified dimension is not valid for the current chart type

转载 作者:行者123 更新时间:2023-12-02 18:45:16 27 4
gpt4 key购买 nike

我正在尝试将 Excel 图表另存为图像。

通过整个代码,我调用多个工作簿,查找所有工作表并保存所有图表。

以下代码适用于 Excel 2007 和 2010(但由于 + 4,有一条可见的水平线和垂直线)。如果我将 Round(shp.Width + 4, 0) 更改为 Round(shp.Width, 0) 我会在 2010 年收到以下错误(但在 2007 年则不会) :

Run-Time error '-2147467259 (80004005)':
The specified dimension is not valid for the current chart type.

Dim shp As Shape
Dim sht As Worksheet

Set sht = Application.ActiveWorkbook.Sheets(shtName)
Set shp = sht.Shapes(chrtName)

shp.CopyPicture xlScreen, xlBitmap

Dim objChart As ChartObject
Set objChart = sht.ChartObjects.Add(200, 200, Round(shp.Width + 4, 0), Round(shp.Height + 4, 0))
objChart.Activate
ActiveChart.Paste
ActiveChart.Export Filename:=fullPath, Filtername:=Right(fullPath, 3)
objChart.Delete

如何避免使用 +4?

我发现了以下内容:

"The problem occurs whenever the default chart type is set to other chart types than the ones you are trying to create. For an example, if you try to create line chart and if the default chart in Excel is OHLC (Candlestick Stock Chart) then Excel will be fast to complain "The specified dimension is not valid for the current chart type". The same occurs even if you try to create charts from VB.NET. Hence, first of all change the default chart type to some basic chart types like Line charts. The problem will be solved." http://www.excelbanter.com/showthread.php?t=204071

如何使用 VBA 执行此操作?

最佳答案

我也遇到了同样的异常。我跟踪问题到了保存路径。

如果保存路径错误,或者指定的路径不存在,则会引发此异常。检查以确保该路径存在。

关于excel - 指定形状宽度会生成错误 : The specified dimension is not valid for the current chart type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11447914/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com