指定形状宽度会产生错误:指定的尺寸对于当前图表类型无效 [英] Specifying shape width generates error: The specified dimension is not valid for the current chart type

查看:61
本文介绍了指定形状宽度会产生错误:指定的尺寸对于当前图表类型无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to save Excel diagrams as images.

在整个代码中,我调用了几个工作簿,查找所有工作表并保存所有图表.

With the whole code I call several workbooks, lookup all worksheets and save all diagrams.

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

The following code works with Excel 2007 and 2010 (but there is a horizontal and vertical line visible because of the + 4). If I change the Round(shp.Width + 4, 0) to Round(shp.Width, 0) I get the following error in 2010 (but not in 2007):

运行时错误'-2147467259(80004005)':
指定的维度对当前图表类型无效.

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?

我发现了以下内容:

只要默认图表类型设置为您要创建的图表类型以外的其他图表类型,就会发生此问题.例如,如果您尝试创建折线图,并且Excel中的默认图表是OHLC(烛台股票),图表),然后Excel会很快抱怨指定的尺寸对于当前图表类型无效".即使您尝试从VB.NET创建图表,也会发生同样的情况.因此,首先将默认图表类型更改为某些基本的图表类型,例如折线图.问题将得到解决." http://www.excelbanter.com/showthread.php?t=204071

如何使用VBA做到这一点?

How can I do this with VBA?

推荐答案

我遇到了同样的异常.我将问题追溯到保存路径.

I got the same exception. I traced the problem to the save path.

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

If the save path is wrong, or the specified path does not exist, then this exception will be raised. Check to make sure that the path exists.

这篇关于指定形状宽度会产生错误:指定的尺寸对于当前图表类型无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆