LegendKey Members

Use the LegendKey object to control the appearance of the series or trendline that corresponds to the legend entry. Use the LegendEntry object’s LegendKey property to get a reference to this collection. The LegendKey object has the following members. Key members (shown in bold) are covered in the following reference section:

Application

Border

ClearFormats

Creator

Delete

Fill

Height

Interior

InvertIfNegative

Left

MarkerBackgroundColor

MarkerBackgroundColorIndex

MarkerForegroundColor

MarkerForegroundColorIndex

MarkerSize

MarkerStyle

Parent

PictureType

PictureUnit

Select

Shadow

Smooth

Top

Width

Setting the key properties of the legend key is equivalent to setting them for their corresponding series. LegendKey simply provides an alternate way to get at those settings. See the Series object in Chapter 16 for descriptions of the preceding key members.

The following code shows using the LegendKey to change series markers and also shows the alternate code using the Series object (commented out):

Sub LegendKeyMembers( ) Dim chrt As Chart, le As LegendEntry, _ lk As LegendKey, sr As Series ' Get the chart. Set chrt = ActiveChart chrt.ChartType = xlLineMarkers ' Make sure chart has a legend. chrt.HasLegend = True For Each le In chrt.Legend.LegendEntries ' Get the legend key Set lk = le.LegendKey lk.MarkerStyle = xlMarkerStyleCircle lk.MarkerSize = 4 Next ' Equivalent code using the ...

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.