Excel VBA:在图表对象中显示线条(轮廓)

时间:2016-09-29 14:16:35

标签: excel excel-vba vba

下面是非常友好地提供给我的其他question on runtime error的代码@davidzemens的一部分。我想展示图表对象的轮廓。

我是否可以使用方法而无需命名图表对象(ChtObj.Name = "ChartName"),选择并激活它然后使用ActiveSheet.Shapes("ChartName").Line.Visible = msoTrue

    'Add the ChtObj frame:
    Set ChtObj = ws.ChartObjects.Add(100, 100, 400, 400)
    'Size the chart, paste the picture in the chart, export
    With ChtObj
        .Width = shp.Width
        .Height = shp.Height
        shp.Copy
        Sleep 1000  '1000 milliseconds = 1 second
        .Chart.Paste
        .Chart.Export Filename:=fname, FilterName:="png"
        .Delete
    End With

1 个答案:

答案 0 :(得分:1)

是的,你可以做到;在导出之前,您必须使用图表对象的.ShapeRange属性(在With ChtObj内):

With ChtObj
    .Width = shp.Width
    .Height = shp.Height
 ' here
    .ShapeRange.Line.Visible = msoTrue
 ' done
    shp.Copy
    Sleep 1000  '1000 milliseconds = 1 second
    .Chart.Paste
    .Chart.Export Filename:=fname, FilterName:="png"
    .Delete
End With