2016-09-29 57 views
1

下面是代碼@davidzemens非常友好地提供給我的其他question on runtime error的一部分。我想展示這個圖表對象的輪廓。Excel VBA:在圖表對象中顯示行(輪廓)

有沒有一種方法可以使用,而不必命名圖表對象(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

是的,你可以做到這一點;你必須使用你的圖表對象的.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 
+0

謝謝你這麼多@JChomel。對不起原來的格式。需要閱讀如何將鏈接鏈接到文本中。 – user110084