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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| Option Explicit
Sub Test()
Dim i As Integer, j As Integer, k As Integer
Dim L As FreeformBuilder
Dim Commune() As String
Dim Shp As Shape
Dim N As Long
Dim Res
With Feuil1
' .Range("P:S").ClearContents
' For Each Shp In .Shapes
' Shp.Delete
' Next Shp
For j = 2 To 16
Res = Formatage(Feuil1.Range("A" & j))
N = .Cells(.Rows.Count, 16).End(xlUp).Row + 1
.Cells(N, 16).Resize(UBound(Res, 1)) = Feuil1.Range("B" & j)
.Cells(N, 17).Resize(UBound(Res, 1), 3) = Res
For i = 1 To UBound(Res, 1)
If Res(i, 1) = "m" Then
Set L = .Shapes.BuildFreeform(msoEditingCorner, Res(i, 2), Res(i, 3))
Else
L.AddNodes msoSegmentLine, msoEditingAuto, Res(i, 2), Res(i, 3)
End If
Next i
With L.ConvertToShape
.Name = Feuil1.Range("B" & j)
k = k + 1
ReDim Preserve Commune(1 To k)
Commune(k) = .Name
End With
Next j
With .Shapes.Range(Commune).Group
.Name = "CarteMaroc"
.ScaleHeight 0.2, msoFalse
.ScaleWidth 0.2, msoFalse
.LockAspectRatio = msoTrue
End With
End With
End Sub
Private Function Formatage(ByVal Svg As String)
Dim i As Integer, k As Integer
Dim Xi As Single, Yi As Single
Dim Autre As Boolean
Dim Tb, Tmp, R()
Tb = Split(Svg)
Do
DoEvents
Select Case Tb(i)
Case "m"
i = i + 1
Tmp = Split(Tb(i), ",")
Xi = Tmp(0)
Yi = Tmp(1)
Case "c", "l", "s"
i = i + 1
Tmp = Split(Tb(i), ",")
Xi = Xi + Tmp(0)
Yi = Yi + Tmp(1)
Case "v"
i = i + 1
Yi = Yi + Tb(i)
Case "V"
i = i + 1
Yi = Tb(i)
Case "h"
i = i + 1
Xi = Xi + Tb(i)
Case "H"
i = i + 1
Xi = Tb(i)
Case "z", "Z"
Exit Do
Case Else
Autre = True
Tmp = Split(Tb(i), ",")
Xi = Xi + Tmp(0)
Yi = Yi + Tmp(1)
End Select
i = i + 1
k = k + 1
ReDim Preserve R(1 To 3, 1 To k)
R(1, k) = IIf(Autre, "", Tb(i - 2))
R(2, k) = Xi
R(3, k) = Yi
Autre = False
Loop While i <= UBound(Tb)
Formatage = Application.Transpose(R)
End Function |
Partager