O'Reilly logo

Programming Excel with VBA and .NET by Steve Saunders, Jeff Webb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required