Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAnn As SldWorks.Annotation
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAnn = swModel.Extension.InsertAnnotationFavorite("C:\monDossierDeNotes\Indice A.sldnotestl", 0.2, 0.2, 0)
swAnn.Layer = "Indice A"
Set swAnn = swModel.Extension.InsertAnnotationFavorite("C:\monDossierDeNotes\Indice B.sldnotestl", 0.2, 0.2, 0)
swAnn.Layer = "Indice B"
Set swAnn = swModel.Extension.InsertAnnotationFavorite("C:\monDossierDeNotes\Indice C.sldnotestl", 0.2, 0.2, 0)
swAnn.Layer = "Indice C"
swModel.WindowRedraw
End Sub
or:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAnn As SldWorks.Annotation
Dim NoteNames As Variant
Dim NoteFolder As String
Dim i As Integer
NoteNames = Array("Indice A", "Indice B", "Indice C")
NoteFolder = "C:\monDossierDeNotes\"
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
For i = 0 To 2
Set swAnn = swModel.Extension.InsertAnnotationFavorite(NoteFolder & NoteNames(i) & ".sldnotestl", 0.2, 0.2, 0)
swAnn.Layer = NoteNames(i)
Next
swModel.WindowRedraw
End Sub
swModel is not declared as a global variable. so despite being assigned in Layer(), it sucks in ChgtComboBox1() we must add: Dim swModel as sldworks.modeldoc2 before main()
In fact, there are a lot of undeclared variables. My suggestion, adds: Explicit Option at the very beginning of the macro and corrects any reporting errors.
Also declare Layer() with: Sub Layer(void) and calls it with: Call Layer(Empty) or: Layer Empty Same for ChgtComboBox1() It will force the macro to launch from main()
It is important that a macro is only one main function (usually main()).
A function is secondary if it has a parameter like (ByVal swModel As ModelDoc2). If a function is secondary but does not need a parameter, the convention is to assign it an empty parameter. (Void)