2017-02-27 65 views
1

在Excel 2016中,有一个选项(图表上的右键单击线)>格式化数据系列>平滑线,使2D线图上的线条平滑。通过Visual Basic 6创建Excel图表时,有什么方法可以启用此选项?在Visual Basic 6中的Excel - 如何用平滑线创建图表?

这link文件,为应用程序在Visual Basic中的选项,但我还没有发现任何针对Visual Basic 6:https://msdn.microsoft.com/en-us/library/office/ff195315(v=office.14).aspx

这是我在Visual Basic 6创建图表代码:

Dim xlApp As excel.Application 
Set xlApp = New excel.Application 
Dim xlWkb As excel.Workbook 
Set xlWkb = xlApp.Workbooks.Open("D:\Documents\Book1.xlsx") 
Dim xlSht As excel.Worksheet 
Set xlSht = xlWkb.Worksheets(1) 
Dim xlChart As excel.Chart 
Set xlChart = xlWkb.Charts.Add 
xlChart.ChartType = xlLine 
xlChart.SetSourceData xlSht.Range("A1:B5"), xlColumns 
xlChart.Visible = xlSheetVisible 
xlChart.Legend.Clear 
xlChart.ChartArea.Font.Size = 15 
xlChart.ChartArea.Font.Color = vbRed 
xlChart.ChartArea.Select 
xlChart.ChartArea.Copy 
Image1.Picture = Clipboard.GetData(vbCFBitmap) ' Image1 is an image control already placed on the Form. 

回答

1

这是图表中每个系列公开的属性(.Smooth),因此您需要循环它们并指定,例如

Dim xlChart As Excel.Chart 
Set xlChart = xlWkb.Charts.Add 

With xlChart 
    .ChartType = xlLine 
    .SetSourceData xlSht.Range("A1:B5"), xlColumns 
    .Visible = xlSheetVisible 
    .Legend.Clear 
    .ChartArea.Font.Size = 15 
    .ChartArea.Font.Color = vbRed 

    Dim i As Long 
    For i = 1 To .FullSeriesCollection.Count 
     .FullSeriesCollection(i).Smooth = True '// <= 
    Next 

    .ChartArea.Select 
    .ChartArea.Copy 
End With 
+0

谢谢,工作完美! – spider93286