Re Bonjour,
Je souhaiterais développer un code qui insère un champ formulaire hérité liste dans des cellules de tableaux (sur plusieurs tableaux mais je pense pouvoir en faire mon affaire une fois la manip connue pour un seul), l'enregistreur de macro me donne un très beau code mais inutilisable quand je le lance, le code s'arrête au passage en mode création sans message d'erreur.

Le code de l'enregistreur et la modification pour la boucle:

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
 
Sub ChampList()
'
' ChampList Macro
'
'
    ActiveWindow.View.ShowXMLMarkup = wdToggle
    ActiveDocument.ToggleFormsDesign
    ActiveDocument.Tables(Tablo).Cell(2, 6).Range.Select
    Selection.HomeKey
    Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormDropDown
    Selection.PreviousField.Select
    With Selection.FormFields(1)
        .Name = "ETAB1DIV1ULIS"
        .EntryMacro = ""
        .ExitMacro = ""
        .Enabled = True
        .OwnHelp = False
        .HelpText = ""
        .OwnStatus = False
        .StatusText = ""
    End With
    Selection.FormFields("ETAB1DIV1ULIS").DropDown.ListEntries.Clear
    Selection.FormFields("ETAB1DIV1ULIS").DropDown.ListEntries.Add Name:=" "
    Selection.FormFields("ETAB1DIV1ULIS").DropDown.ListEntries.Add Name:="OUI"
    Selection.FormFields("ETAB1DIV1ULIS").DropDown.ListEntries.Add Name:="NON"
    ActiveWindow.View.ShowXMLMarkup = wdToggle
    ActiveDocument.ToggleFormsDesign
End Sub

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
 
ActiveDocument.Tables(Tablo).Cell(i, 6).Range.Select
 Selection.HomeKey
 
 ActiveWindow.View.ShowXMLMarkup = wdToggle
    ActiveDocument.ToggleFormsDesign
    Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormDropDown
    Selection.PreviousField.Select
    With Selection.FormFields(1)
        .Name = "ETAB" & Tablo & "DIV" & i & "ULIS"
        .EntryMacro = ""
        .ExitMacro = ""
        .Enabled = True
        .OwnHelp = False
        .HelpText = ""
        .OwnStatus = False
        .StatusText = ""
    End With
    Selection.FormFields("ETAB" & Tablo & "DIV" & i & "ULIS").DropDown.ListEntries.Clear
    Selection.FormFields("ETAB" & Tablo & "DIV" & i & "ULIS").DropDown.ListEntries.Add Name:=" "
    Selection.FormFields("ETAB" & Tablo & "DIV" & i & "ULIS").DropDown.ListEntries.Add Name:="OUI"
    Selection.FormFields("ETAB" & Tablo & "DIV" & i & "ULIS").DropDown.ListEntries.Add Name:="NON"
    ActiveWindow.View.ShowXMLMarkup = wdToggle
    ActiveDocument.ToggleFormsDesign