Reputation: 57
In Excel 2016, there is an option under (Right Click Line on chart) > Format Data Series > Smoothed Line, which makes the line on a 2D Line Chart smooth. When creating an Excel chart through Visual Basic 6, is there any way to enable this option?
This link documents the option in Visual Basic for Applications, but I have not found anything for Visual Basic 6: https://msdn.microsoft.com/en-us/library/office/ff195315(v=office.14).aspx
Here is my code for creating a chart in 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.
Upvotes: 1
Views: 857
Reputation: 175826
This is a property (.Smooth
) exposed by each series on the chart, so you need to loop them and assign, E.g.
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
Upvotes: 1