Ga naar hoofdinhoud

Hoe een vervolgkeuzelijst met kleurcodering in de Word-tabel invoegen?

Stel dat ik een tabel in mijn Word-document heb en nu wil ik een kleurgecodeerde vervolgkeuzelijst invoegen in een kolom van de tabel. Dit betekent dat wanneer ik een optie uit de vervolgkeuzelijst selecteer, de celkleur rood wordt en wanneer ik een andere optie in de vervolgkeuzelijst selecteer, de celkleur groen wordt zoals in de volgende schermafbeelding. Hoe zou je deze taak in Word-document kunnen oplossen?

dropdownmenu met doc kleurcode

Voeg kleurgecodeerde vervolgkeuzelijst in Word-document in met VBA-code


Voeg kleurgecodeerde vervolgkeuzelijst in Word-document in met VBA-code

De volgende stappen kunnen u helpen om deze taak naar behoefte te voltooien. Voeg eerst de vervolgkeuzelijst in en pas vervolgens de kleur voor de vervolgkeuzelijst toe. Doe dit als volgt:

1. Selecteer een cel in de tabel waarin u de vervolgkeuzelijst wilt invoegen en klik op Ontwikkelaar > Inhoudsbeheer vervolgkeuzelijst pictogram, zie screenshot:

dropdownmenu met doc kleurcode 1

2. De vervolgkeuzelijst wordt in de specifieke cel ingevoegd en klikt vervolgens op Ontwikkelaar > Properties, zie screenshot:

dropdownmenu met doc kleurcode 2

3. In de Eigenschappen van inhoudscontrole dialoogvenster, voer dan de volgende bewerkingen uit:

(1.) Voer de titelnaam in het Titel tekstvak;

(2.) Klik Toevoegen knop ga naar de Keuze toevoegen dialoog;

(3.) In het Keuze toevoegen dialoogvenster, typ het vervolgkeuzelijstitem in het Weergavenaam tekstvak.

dropdownmenu met doc kleurcode 3

4. Herhaal stap 3 om naar behoefte andere items in de vervolgkeuzelijst in te voegen.

5. Nadat u de eerste vervolgkeuzelijst hebt gemaakt, kunt u deze naar behoefte kopiëren en in andere cellen plakken. Zie screenshot:

dropdownmenu met doc kleurcode 4

6. Dan moet u een VBA-code toepassen, houd de ALT + F11 toetsen om de te openen Microsoft Visual Basic voor toepassingen venster.

7. In de Microsoft Visual Basic voor toepassingen venster, dubbelklik Dit document van het Project-Project deelvenster om de modus te openen en kopieer en plak vervolgens de volgende code in de lege module.

VBA-code: voeg een kleurgecodeerde vervolgkeuzelijst in de tabel van een Word-document in:

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "Complete"
                .Cells(1).Shading.BackgroundPatternColor = wdColorRed
            Case "In Progress"
                .Cells(1).Shading.BackgroundPatternColor = wdColorGreen
            Case "Not Start"
                .Cells(1).Shading.BackgroundPatternColor = wdColorBlue
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub

dropdownmenu met doc kleurcode 5

Note: In de bovenstaande code, Status is de titelnaam wanneer u de vervolgkeuzelijst maakt, en Volledige, In Behandeling, Niet starten zijn de items van de vervolgkeuzelijst, u kunt ze wijzigen in uw eigen. En u kunt de kleur ook aanpassen aan uw behoefte.

8. Sla vervolgens het codevenster op en sluit het, nu, wanneer u een item uit de vervolgkeuzelijst selecteert, wordt de relatieve kleur gevuld met de cel, zie screenshot:

dropdownmenu met doc kleurcode


 

Beste Office-productiviteitstools

Kutools for Word - Verbeter uw woordervaring met Over 100 Opmerkelijke kenmerken!

🤖 Kutools AI-assistent: Transformeer uw schrijven met AI - Inhoud genereren  /  Herschrijf tekst  /  Documenten samenvatten  /  Informeer voor informatie gebaseerd op document, allemaal binnen Word

📘 Documentbeheersing: Pagina's splitsen  /  Voeg documenten samen  /  Selectie exporteren in verschillende formaten (PDF/TXT/DOC/HTML...)  /  Batchconversie naar PDF  /  Pagina's exporteren als afbeeldingen  /  Meerdere bestanden tegelijk afdrukken...

Inhoud bewerken: Batch zoeken en vervangen over meerdere bestanden  /  Formaat van alle afbeeldingen wijzigen  /  Tabelrijen en -kolommen transponeren  /  Converteer tabel naar tekst...

🧹 Moeiteloos schoon: Veeg weg Extra ruimtes  /  Sectie-onderbrekingen  /  Alle koppen  /  Tekstvakken  /  hyperlinks  / Ga voor meer verwijdergereedschappen naar onze Groep verwijderen...

Creatieve invoegingen: Invoegen Duizend scheidingstekens  /  Vink vakjes aan  /  Radio knoppen  /  QR Code  /  Barcode  /  Diagonale lijntabel  /  Vergelijking bijschrift  /  Bijschrift bij afbeelding  /  Tabel titel  /  Meerdere afbeeldingen  / Ontdek meer in de Groep invoegen...

???? Precisieselecties: Vaststellen specifieke pagina's  /  tafels  /  vormen  /  kop paragrafen  / Verbeter de navigatie met meer Selecteer functies...

Sterverbeteringen: Navigeer snel naar elke locatie  /  automatisch herhaalde tekst invoegen  /  naadloos schakelen tussen documentvensters  /  11 Conversiehulpmiddelen...

👉 Wil je deze functies proberen? Kutools voor Word biedt een Gratis proefperiode van 60-dag, zonder beperkingen! 🚀
 

 

Comments (54)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
hello . i tried but it not go.
This comment was minimized by the moderator on the site
bonjour, je ne parviens pas à enregistrer
This comment was minimized by the moderator on the site
I have a word document that i would like some help with, in short, i have a large inspection table, items either comply, don't, further information etc. I currently use a simple drop-down option which has 5-6 options, ill like a selection option that when different options are selected, that changes the cells/row to a red or green etc, and then also (If possible) updates a Summary Table? is this possible, I'll pay someone for a general templet i can the work on....

Thank you in advance....
This comment was minimized by the moderator on the site
Hello, peter,
Did you mean to select an item from the drop down list, and a specific background color is filled for that row?
Please view the attachment to check if it is your need. If this is not your need, please give your problem more clearly.
Thank you!
This comment was minimized by the moderator on the site
Almost, by changing the drop-down tab the whole row changes color, perfect, thank you, however the magic is then coping the row (Yet only rows that don't comply or need further info etc... ) and placing it in a summary table at the top of the page in another table etc... getting them all to keep adding would be great in a summary table.

I can then alter the summary table as things change, and it updated the main parent table .... I'm not sure this is possible.

I'm happy to have a Teams Meeting to get this working, it would be apricated as it is doing my head in...

This comment was minimized by the moderator on the site
Hi, this is great, got me over a major problem with my fillable form. However, when I go to protect my fillable form, it brings up the debugger box? any idea how i can overcome this?
This comment was minimized by the moderator on the site
Thank you, i have managed to change the background colour. Is there a way i can change the text to white?
This comment was minimized by the moderator on the site
Hello, Emily,
To change the text color to white, please apply the following code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "Complete"
                .Cells(1).Shading.BackgroundPatternColor = wdColorRed
                .Cells(1).Range.Font.Color = wdColorWhite
            Case "In Progress"
                .Cells(1).Shading.BackgroundPatternColor = wdColorGreen
                .Cells(1).Range.Font.Color = wdColorWhite
            Case "Not Start"
                .Cells(1).Shading.BackgroundPatternColor = wdColorBlue
                .Cells(1).Range.Font.Color = wdColorWhite
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
What code do you add so it goes back to the normal colours (both background and text) when you select "Choose an item" from dropdown list after previously selecting a case
This comment was minimized by the moderator on the site
Hello, Usama,
In this case, the code in this article can help you. When uou select an item and then do back to choosing "Choose an item", the backdround color will not be filled.
Please try again. Thank you!
This comment was minimized by the moderator on the site
Well done! Is it possible to activate different cells (independent of row and column) with an item of the ContentControl... e.g. if we put the alphabet of English letters in a table with 6 rows and 5 columns and want to activate the vowels or the consonants?
This comment was minimized by the moderator on the site
Well done! Is it possible to activate different cells (independent of row and column) with an item of the ContentControl... e.g. if we put the alphabet of English letters in a table with 6 rows and 5 columns and want to activate the vowels or the consonants?
This comment was minimized by the moderator on the site
Hi I want a drop down list of colours but i do not want any text in the cells, i just want my users to be able to choose a colour as I am creating a RAG rated form.

is this possible?

thanks.
This comment was minimized by the moderator on the site
Probably way too late, but in case anyone else is wondering, you can probably do something like this by just adapting the code a bit.

adjust the range.font.color line with the same wd color code as the code above. Its not perfect but if the font is the same color as the highlight, you wont be able to visually see the difference
This comment was minimized by the moderator on the site
I have pasted the code and can see my drop down options (the text) but when I choose them, the background colors don't apply. Do you have any way to help me figure out what I may be doing wrong? Please and thank you! This is exactly what I'm hoping to do in my document, if I can make it work. Thanks!
This comment was minimized by the moderator on the site
Hello, Susan
You should check if the corresponding text in the VBA code has been mofified to your own contents.

Note: In the above code, Status is the title name when you creating the drop down list, and Complete, In Progress, Not Start are the items of the drop down list, you can change them to your own. And you can also change the color to your need.

If there is still problem after changing the text, you can upload the attachment word file and we will help you check it.
Thank you!
This comment was minimized by the moderator on the site
I am having the same issue.
I have changed the titles names in the code and followed the rest of the instructions.
Can you please tell me what I may have done wrong?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations