Je cherche a tracer une courbe, les coordonnees sont dans un tableau, le resultat est un seul segment passant par tous les points.
le code important est en rouge.
Le code en VBE:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Sub dessin_ligne()
        Sheets("COORDONNEES").Select
a = 1
fin_boucle = ActiveSheet.UsedRange.Rows.Count
XX = (Cells(3, 1).Value) * a
YY = (Cells(3, 2).Value) * a
    Sheets("CIRCUIT2").Select
With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, XX, YY)
For C = 4 To fin_boucle
If C = fin_boucle Then
X1 = X + 1
Y1 = Y + 1
Else
        Sheets("COORDONNEES").Select
X = (Cells(C, 1).Value) * a
Y = (Cells(C, 2).Value) * a
X1 = (Cells(C + 1, 1).Value) * a
Y1 = (Cells(C + 1, 2).Value) * a
End If
    Sheets("CIRCUIT2").Select
        .AddNodes msoSegmentLine, msoEditingAuto, X, Y
        .AddNodes msoSegmentLine, msoEditingAuto, X1, Y1
Next
        .ConvertToShape.Select
End With
Set myDocumenT = Worksheets("CIRCUIT2")
myDocumenT.Shapes.SelectAll
    Selection.ShapeRange.Line.Weight = 8#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.SchemeColor = 22
End Sub
je pense avoir reussi a programmer une partie des commandes mais je ne reussi pas a afficher le segment
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
// essai d'utilisation des fonctions de dessin mono-traits multi-points
Variant msoEditingAuto, msoSegmentLine, vLigne, Select;
        vWorksheet = vXLWorkbook.OlePropertyGet("Worksheets", 1);
        vLigne = vWorksheet.OlePropertyGet("Shapes").OleFunction("BuildFreeform", msoEditingAuto, 1, 1);
        vLigne.OleFunction("AddNodes", msoSegmentLine, msoEditingAuto, 1, 1);
        vLigne.OleFunction("AddNodes", msoSegmentLine, msoEditingAuto, 120, 210);
        vLigne.OleFunction("ConvertToShape").OleFunction("Select");
//
La derniere ligne me donne une erreur ".....provoque une exception"