View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Multiple chart selection in Excel 2007

I prefer to avoid using SELECTION whenever possible as it slows down
execution. You may want to try something like this

Dim aWS as Excel.Worksheet
Dim ChtObj as Excel.ChartObject

set aWS = ActiveSheet

for each ChtObj in aWS.ChartObjects
'Do what you'd do.
next ChtObj

HTH,
Barb Reinhardt

"Luca Brasi" wrote:

My add-in should process all charts the user currently has selected. Now I
ran into a problem when the user has selected several charts (but not all!)
on a worksheet.
It looks to me as if there is a bug in the "Selection" object in Excel 2007.

Let's say I select two out of three charts on a worksheet and run the sample
code below. Instead of the selected charts, the first two charts I inserted
into the worksheet are processed.

Am I doing something wrong or can someone confirm this is a bug in Excel
2007? Knows someone a workaround? Thanks for any hints, Luca

'*** Sample code
Sub Test()
Dim i As Long
Dim obj As Object
If Windows.Count 0 Then
If TypeName(ActiveSheet) = "Worksheet" Then
If TypeName(ActiveWindow.Selection) = "DrawingObjects" Then
For i = 1 To ActiveWindow.Selection.Count
Set obj = ActiveWindow.Selection(i)
If TypeName(obj) = "ChartObject" Then
' toggle legend to show which charts are processed
obj.Chart.SetElement IIf(obj.Chart.HasLegend, _
msoElementLegendNone, msoElementLegendBottom)
End If
Next i
End If
End If
End If
End Sub
'*** End of code