Salt la conținutul principal

Cum se introduce o listă derulantă cu cod color în tabelul Word?

Presupunând că am un tabel în documentul meu Word și acum vreau să inserez o listă derulantă colorată într-o coloană a tabelului. Înseamnă că atunci când selectez o opțiune din meniul derulant, culoarea celulei devine roșie, iar când selectez o altă opțiune în meniul derulant, culoarea celulei devine verde după cum se arată în următoarea captură de ecran. Cum ați putea rezolva această sarcină în documentul Word?

drop-down cod cod color

Introduceți lista derulantă codată în culori în documentul Word cu cod VBA


Introduceți lista derulantă codată în culori în documentul Word cu cod VBA

Următorii pași vă pot ajuta să finalizați această sarcină după cum aveți nevoie, mai întâi, introduceți lista verticală și apoi aplicați culoarea pentru lista verticală. Vă rugăm să faceți acest lucru:

1. Selectați o celulă din tabel în care doriți să introduceți meniul derulant, apoi faceți clic pe Dezvoltator > Controlul conținutului listei drop-down pictogramă, vezi captura de ecran:

meniul drop-down codat în culori doc 1

2. Meniul derulant este introdus în celula specifică, apoi faceți clic Dezvoltator > Proprietăţi, vezi captura de ecran:

meniul drop-down codat în culori doc 2

3. În Proprietăți de control al conținutului caseta de dialog, vă rugăm să efectuați următoarele operații:

(1.) Introduceți numele titlului în Titlu casetă de text;

(2.) Faceți clic pe Adăuga butonul mergeți la Adăugați alegere dialog;

(3.) În Adăugați alegere caseta de dialog, tastați elementul din lista derulantă în Numele afisat casetă de text.

meniul drop-down codat în culori doc 3

4. Repetați Pasul 3 pentru a insera alte elemente din lista derulantă după cum aveți nevoie.

5. După ce ați creat prima listă derulantă, o puteți copia și lipi în alte celule după cum aveți nevoie. Vedeți captura de ecran:

meniul drop-down codat în culori doc 4

6. Apoi ar trebui să aplicați un cod VBA, vă rugăm să țineți apăsat butonul ALT + F11 tastele pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.

7. În Microsoft Visual Basic pentru aplicații fereastră, faceți dublu clic Acest document de la Proiect-Proiect pentru a deschide modul, apoi copiați și lipiți următorul cod în modulul gol.

Cod VBA: introduceți o listă derulantă cu cod color în tabelul unui document Word:

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

meniul drop-down codat în culori doc 5

notițe: În codul de mai sus, Stare este numele titlului la crearea listei derulante și Completa, În Progres, Nu începe sunt elementele din lista derulantă, le puteți schimba la ale dvs. Și puteți schimba culoarea în funcție de nevoile dvs.

8. Apoi salvați și închideți fereastra de cod, acum, când selectați un element din lista derulantă, culoarea sa relativă va fi completată cu celula, vedeți captura de ecran:

drop-down cod cod color


 

Cele mai bune instrumente de productivitate de birou

Kutools pentru Cuvânt - Crește-ți experiența Word cu Over 100 Caracteristici remarcabile!

🤖 Asistent AI Kutools: Transformă-ți scrisul cu AI - Generați conținut  /  Rescrie textul  /  Rezumat documente  /  Solicitați informații pe baza Documentului, toate în Cuvânt

📘 Stăpânirea documentelor: Pagini împărțite  /  Fuzionați documente  /  Exportați selecția în diferite formate (PDF/TXT/DOC/HTML...)  /  Conversie lot în PDF  /  Exportați paginile ca imagini  /  Imprimați mai multe fișiere simultan...

Editarea continutului: Găsiți și înlocuiți în lot peste mai multe fișiere  /  Redimensionați toate imaginile  /  Transpuneți rânduri și coloane de tabel  /  Convertiți tabelul în text...

🧹 Curățare fără efort: Îndepărtați Spații suplimentare  /  Secțiuni pauze  /  Toate anteturile  /  Casete text  /  hiperlinkuri  / Pentru mai multe instrumente de îndepărtare, mergeți la nostru Eliminați grupul...

Inserții creative: Inserați Mii de separatori  /  Casete de bifare  /  Butoane radio  /  QR Code  /  coduri de bare  /  Tabel cu linii diagonale  /  Legenda ecuației  /  Image Caption  /  Legenda tabelului  /  Imagini multiple  / Descoperiți mai multe în Inserați grupul...

???? Selectii de precizie: Repera cu precizie pagini specifice  /  tabele  /  forme  /  paragrafele de titlu  / Îmbunătățiți navigarea cu mai mult Selectați caracteristici...

Îmbunătățiri de stele: Navigați rapid în orice locație  /  inserarea automată a textului repetitiv  /  comutați fără probleme între ferestrele documentelor  /  11 Instrumente de conversie...

???? Vrei să încerci aceste funcții? Kutools pentru Word oferă a 60-zi de încercare gratuită, fără limitări! 🚀
 

 

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