我正在尝试将excel-vba中的图表保存为图像。为此,我使用下面的代码。这适用于Excel 2007,但Excel 2010需要更大的维度才能满足需要加权的图表对象。所以我使用+ 4而不是+ 1.这样做我在底部和右侧有一条线(看起来像一个框架)。有人知道如何摆脱这些界线吗?
'1. copy to clipboard
'2. create new chart object with greater dimensions (office 2010 requirement), round because shape size is double (e.g. 200.5px)
'3. Paste clipboard content
'4. export chart, delete afterwards
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 + 1, 0), Round(shp.Height + 1, 0))
'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