Créer des listes déroulantes dépendantes avec WORD à plusieurs niveaux (ou listes en cascade)
3 min read
11 months ago
Published on Sep 19, 2024
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Introduction
This tutorial will guide you through creating dependent drop-down lists in Microsoft Word, allowing for dynamic and efficient data entry in forms. By the end of this guide, you will be able to create multiple levels of cascading drop-down lists tailored to your needs.
Step 1: Create a Basic Form in Microsoft Word
- Open Microsoft Word and create a new document.
- Go to the "Developer" tab. If it's not visible, enable it by:
- Clicking on "File" > "Options" > "Customize Ribbon".
- Check the "Developer" box in the right pane and click "OK".
- In the "Developer" tab, click on "Legacy Tools" and select "Drop-Down List Content Control".
Step 2: Add the First Drop-Down List
- Click on the location in the document where you want to insert the first drop-down list.
- Select the drop-down list control from the "Legacy Tools".
- Right-click on the drop-down list and select "Properties".
- Add items to the drop-down by clicking "Add" and entering the desired options (e.g., "Réunion", "Rendez-vous").
- Click "OK" to save the changes.
Step 3: Create the Second Dependent Drop-Down List
- Insert another drop-down list below the first one, following the same steps as above.
- Right-click and select "Properties".
- Instead of adding items directly, you will use VBA code to populate this list based on the selection of the first drop-down.
Step 4: Using VBA to Populate the Second Drop-Down List
- Press
Alt + F11
to open the VBA editor. - Insert a new module by right-clicking on any of the items in the Project Explorer and selecting "Insert" > "Module".
- Copy and paste the following VBA code:
Sub PopulateddType2()
Select Case ActiveDocument.FormFields("ddObjet1").Result
Case "Réunion"
With ActiveDocument.FormFields("ddType2").DropDown.ListEntries
.Clear
.Add "Réunion d'information"
.Add "Séminaire"
.Add "Réunion du personnel"
End With
Case "Rendez-vous"
With ActiveDocument.FormFields("ddType2").DropDown.ListEntries
.Clear
.Add "Entretien individuel"
.Add "Groupe"
.Add "Entretien téléphonique"
End With
End Select
End Sub
- Replace
"ddObjet1"
and"ddType2"
with the actual names of your drop-down fields. - Close the VBA editor.
Step 5: Create the Third Dependent Drop-Down List
- Insert a third drop-down list in the same manner as the previous steps.
- This list will be populated based on the selection from the second drop-down.
Step 6: Using VBA for the Third Drop-Down List
- Open the VBA editor again and insert another module.
- Copy and paste the following VBA code:
Sub PopulateddLieu3()
Select Case ActiveDocument.FormFields("ddType2").Result
Case "Réunion d'information"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Salle 1"
.Add "Salle 2"
End With
Case "Séminaire"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Salle 3"
.Add "Salle 4"
End With
Case "Réunion du Personnel"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Salle 10"
.Add "Salle 11"
End With
Case "Entretien individuel"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Salle 5"
.Add "Salle 6"
End With
Case "Groupe"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Salle 7"
.Add "Salle 8"
End With
Case "Entretien téléphonique"
With ActiveDocument.FormFields("ddLieu3").DropDown.ListEntries
.Clear
.Add "Bureau 1"
.Add "Bureau 2"
End With
End Select
End Sub
- Replace
"ddType2"
and"ddLieu3"
with the correct field names.
Conclusion
You have successfully created a multi-level dependent drop-down list in Microsoft Word. This setup helps streamline data entry, making forms easier to manage. For further customization, explore additional VBA commands or consider expanding your forms with more dependent lists.