THREAD SUMMARY.
This thread is hard to follow but i will try to do a grand summary.
First of all thanks to all for the comments and advice. They did contribute to helping me with this issue although none "fully solves" it.
THIS AREA OF VBA IS A MESS. It does not really work properly, and i cannot find properties to make it fully work. Although due to advice in this thread have cobbled together something that "almost" does what i need so it will have to be "good enough".
Properties exist for VBA objects that are not even listed in the object browser for that object.
The problem:
- In the UI, using the "Format Data point" dialog, you can select alot of formatting options that apply to that single point's marker to make it different from the other points in the series, including border type (line, dashes, etc), border color, border thickness.
- There are not sufficient VBA properties to duplicate this behavior in VBA.
- What the recorder records when you perform the actions in the dialog, when replayed, change not only the formats of the point that you selected, but also applies the formats you selected for the border of the marker, to the line segment of the chart that lead to the point. In other words, "border marker" and "line segment" are mingled in VBA but are separate in the UI.
What I wanted to accomplish in VBA.
As series (Scatterplot) has no markers (line only) and is line type msoSysDot. I want the FINAL point (only) to have a marker, that the marker match the series line in Width and Color, but be msoLineSolid.
Partial solutions.
- The link posted by Zot to an Excel 2007 article identifies this exact issue. (So i guess Microsoft has not fixed this issue for 14 years!). It suggests an approach of accepting the "defect" in the macro that it changes the line segment also, and then after that runs, try to change the line segment back. This works for some but not all of the properties. Specifically, there is not a property (that I can find) that will allow you to separately control the DashStyle property for the line segment and for the marker border. They have to match (and i do not want them to; I want the marker border to be msoLineSolid while the chart line segment needs to be msoLineSysDot).
- The properties mentioned by Michael M are helpful as they do affect only the marker, not the line segment. But, there are not enough of them to cover everything that the UI allows you to do. The property provided, Point.Format.Line.Weight, does not correspond to the "Width" property in the UI; some widths you can select in the UI cannot be duplicated in VBA and the number you do set in your code is "mysteriously rounded" and you have to play around to find a setting that works "somewhat closely to what you want". And this property is applied by VBA to both the marker border and to the line segment. The property Point.MarkerForegroundColorIndex does not use the same color scheme that the UI offers, and so again you have to play around and guess at numbers and settle for one that is "more or less ok". Microsoftdocumentation is incoorrect for this value, stating that it has only 2 values, Automatic and None, but in fact it is a series of colors that seem to work from 0 to approximately 60.
=======APPENDIX TO THIS POST========
In case anybody wants to work on this issue any further.
Macro to run to create a chart to experiment on.
Sub Create_Example()
'
' Macro19 Macro
'
'
ActiveCell.FormulaR1C1 = "1"
Range("A2").Select
ActiveCell.FormulaR1C1 = "2"
Range("A3").Select
ActiveCell.FormulaR1C1 = "3"
Range("A4").Select
ActiveCell.FormulaR1C1 = "4"
Range("B1").Select
ActiveCell.FormulaR1C1 = "2"
Range("B2").Select
ActiveCell.FormulaR1C1 = "4"
Range("B3").Select
ActiveCell.FormulaR1C1 = "3"
Range("B4").Select
ActiveCell.FormulaR1C1 = "6"
Range("A1:B4").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatterLinesNoMarkers).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$B$4")
ActiveChart.FullSeriesCollection(1).Select
Selection.MarkerStyle = -4142
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.DashStyle = msoLineSysDot
.Weight = 2
End With
End Sub
Chart created while recording in the UI. Select the last point in the series. In the "Format Data Point"dialog, for the Marker: set color, border width, border line type.
Macro recorded while creating the above chart in the UI.
Sub Macro_As_Recorded()
'
' Macro23 Macro
'
' MAKE SURE CHART IS SELECTED BEFORE RUNNIN THIS RECORDED MACRO.
' ActiveSheet.ChartObjects("Chart 11").Activate
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).Points(4).Select
With Selection
.MarkerStyle = -4142
.MarkerSize = 5
End With
Selection.MarkerStyle = 2
Selection.MarkerSize = 10
Selection.Format.Fill.Visible = msoFalse
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.Weight = 3
End With
With Selection.Format.Line
.Visible = msoTrue
.DashStyle = msoLineSolid
End With
End Sub
The chart as it will appear after replaying the above recorded macro on the original, clean example case.
Macro I now use, "best i can do" with some comments.
Sub Attempt_Fix_Line()
'This can be run on a clean example
'MAKE SURE CHART IS SELECTED BEFORE RUNNING THIS MACRO
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).Points(4).Select
Selection.MarkerStyle = xlMarkerStyleCircle
Selection.MarkerSize = 10
Selection.Format.Fill.Visible = msoFalse
'This does not allow all of the same colors as the UI.
Selection.MarkerForegroundColorIndex = 0 '0 is black
'Weight is not the same as "width" in the UI. Have to guess to find right Weight
'Not all width's in the UI can be duplicated with Weight, as it is rounded (strangely)
'This changes both chart line segment and border width. Cannot control them separately.
'Fortunately i can live with "2" for both.
Selection.Format.Line.Weight = 2
'Cannot find a way to control dash style. It now seems to default to Solid so ok
'But in other cases was getting Dashed lines for the marker border that i did not want
' and could not fix.
End Sub