Wenn Sie die x- und y-Werte haben Sie sie direkt auf einem Arbeitsblatt zeichnen können. Das folgende ist ein Beispiel, das zufällig x- und y-Koordinaten für 5 Punkte erzeugt. Ein kleiner gefüllter Kreis wird an jedem Punkt gezeichnet. Zwischen dem vorherigen und dem nächsten Punkt wird eine Linie gezogen, die eine geschlossene Schleife bildet.
Um zu demonstrieren, wie Sie die Linienfarben auswählen können, färbe ich sie abwechselnd grau und blau, um Ihnen eine Vorstellung davon zu geben, wie Sie sie basierend auf anderen Kriterien selektiv einfärben können.
vbBlue gehört zu einer voreingestellten Farbpalette (siehe hierzu link) weshalb es nicht deklariert werden muss - im Gegensatz zu vbGray.
Option Explicit
Sub drawALine(xFrm As Double, yFrm As Double, xTo As Double, yTo As Double, c As Long)
With ActiveSheet.Shapes.AddLine(xFrm, yFrm, xTo, yTo).Line
.DashStyle = msoLineDashDotDot
.ForeColor.RGB = c
End With
End Sub
Sub drawNode(r As Double, x As Double, y As Double, c As Long)
With ActiveSheet.Shapes.AddShape(msoShapeOval, x - r/2, y - r/2, r, r)
.Fill.ForeColor.RGB = c
End With
End Sub
Sub ConnectedOverLappingLoop()
Dim xMax As Double, yMax As Double, x1 As Double, y1 As Double
Dim xFrm As Double, yFrm As Double, xTo As Double, yTo As Double
Dim radius As Double
Dim vbGray As Long, clr As Long
xMax = 200
yMax = 200
radius = 5
vbGray = RGB(150, 150, 150)
xFrm = Rnd() * xMax
yFrm = Rnd() * yMax
x1 = xFrm
y1 = yFrm
clr = vbBlue
drawNode radius, x1, y1, vbBlue
Dim i As Integer
For i = 1 To 5:
xTo = Rnd() * xMax
yTo = Rnd() * yMax
drawNode radius, xTo, yTo, vbBlue
drawALine xFrm, yFrm, xTo, yTo, clr
xFrm = xTo
yFrm = yTo
If clr = vbBlue Then
clr = vbGray
Else
clr = vbBlue
End If
Next
drawALine xFrm, yFrm, x1, y1, clr
End Sub