1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| '--- dans un module normal
Sub ListerToutesLesFormes()
Dim ws As Worksheet, shp As Shape, kR1 As Long, kR2 As Long, i As Long, s As String
Set ws = ThisWorkbook.Worksheets("Liste")
kR1 = 2
kR2 = 2
On Error Resume Next
Debug.Print "Nombre total de formes : " & ws.Shapes.Count
For Each shp In ThisWorkbook.Worksheets("Carte").Shapes
Debug.Print "Nom: " & shp.Name & ", Type: " & shp.Type & ", ID: " & shp.ID
'--- Si cette forme contient des sous-formes (groupe)
If shp.Type = msoGroup Then
Debug.Print " est un groupe contenant " & shp.GroupItems.Count & " éléments :"
For i = 1 To shp.GroupItems.Count
With shp.GroupItems(i)
If .Type = 1 Then '--- rectangle ou ellipse
Range("A" & kR1) = .Name
Range("B" & kR1) = .Type
Range("C" & kR1) = .Top + .Height / 2
Range("D" & kR1) = .Left + .Width / 2
s = .TextFrame.Characters.Text
Range("E" & kR1) = s
Range("F" & kR1) = Mid(s, InStr(s, Chr(10)) + 1)
kR1 = kR1 + 1
Else '--- autre, normalement 5 = textbox
Range("G" & kR2) = .Name
Range("H" & kR2) = .Type
Range("I" & kR2) = .Top + .Height / 2
Range("J" & kR2) = .Left + .Width / 2
kR2 = kR2 + 1
End If
End With
Next i
End If
Next shp
On Error GoTo 0
End Sub
'--- dans la feuille Liste
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 1 And Target.Column <> 7 Then Exit Sub
If Target.Value = "" Then Exit Sub
Dim oShape As Object
ThisWorkbook.Worksheets("Carte").Select
Set oShape = ThisWorkbook.Worksheets("Carte").Shapes("GroupeCarte").GroupItems(Target)
Debug.Print Target, oShape.Top, oShape.Left
'--- pose la flèche près du coin supérieur gauche de la forme
ThisWorkbook.Worksheets("Carte").Shapes("Ceci").Select
Selection.Top = oShape.Top - Selection.Height / 2
Selection.Left = oShape.Left - Selection.Width / 2
'--- repositionne la zone affichée
If Selection.topLeftCell.Row > (Application.ActiveWindow.VisibleRange.Rows.Count / 2) Then
Application.ActiveWindow.ScrollRow = Selection.topLeftCell.Row - Application.ActiveWindow.VisibleRange.Rows.Count / 2
Else
Application.ActiveWindow.ScrollRow = 1
End If
If Selection.topLeftCell.Column > Application.ActiveWindow.VisibleRange.Columns.Count / 2 Then
Application.ActiveWindow.ScrollColumn = Selection.topLeftCell.Column - Application.ActiveWindow.VisibleRange.Columns.Count / 2
Else
Application.ActiveWindow.ScrollColumn = 1
End If
'---
oShape.Select
End Sub |
Partager