1

我正在尝试将 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
4

0 回答 0