Microsoft Office Tutorials and References
In Depth Information
Determining whether the active chart is embedded
Range if a range is selected, Series if a chart series is selected, PlotArea if a chart’s
plot area is selected, and so on.
This macro works fine — except when an embedded chart is selected and the
macro is executed by clicking a button on a sheet. In such a case, the button
temporarily gets the focus, and the chart is deactivated, leaving the ChartObject
selected. Consequently, the message box always displays ChartObject .
Following is a modified version of this macro that works regardless of how the
macro is executed (see Figure 16-2). If the macro detects that the type of selection
is a ChartObject , it then activates the selection, which causes the previously
selected chart element to be selected. This modification, however, introduces
another minor problem: The macro cannot determine whether a ChartObject is
selected (that is, the user selected the chart by using Ctrl+Click).
If ActiveChart Is Nothing Then
If TypeName(Selection) = “ChartObject” Then Selection.Activate
Figure 16-2: Using a message box to display the type of object that’s selected