user110084
user110084

Reputation: 279

Excel VBA: show line (outline) in chart object

Below is part of the code @davidzemens very kindly provided to my other question on runtime error. I would like to show the outline of the chartobject.

Is there a method I could use without having to name the chartobject (ChtObj.Name = "ChartName"), select and activate it and then using 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

Upvotes: 1

Views: 586

Answers (1)

J. Chomel
J. Chomel

Reputation: 8395

Yes you can do it; You have to use .ShapeRange property of your chart object (inside the With ChtObj), before you export:

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

Upvotes: 1

Related Questions