Ir para o conteúdo principal

Como inserir uma lista suspensa codificada por cores na tabela do Word?

Suponha que eu tenha uma tabela em meu documento do Word e, agora, desejo inserir uma lista suspensa codificada por cores em uma coluna da tabela. Isso significa que quando eu seleciono uma opção no menu suspenso, a cor da célula se torna vermelha, e quando eu seleciono outra opção no menu suspenso, a cor da célula se torna verde como mostrado na imagem a seguir. Como você resolveria esse trabalho em um documento do Word?

doc drop down codificado por cores

Insira a lista suspensa codificada por cores no documento do Word com código VBA


Insira a lista suspensa codificada por cores no documento do Word com código VBA

As etapas a seguir podem ajudá-lo a concluir esta tarefa conforme necessário, primeiro, insira a lista suspensa e, em seguida, aplique a cor para a lista suspensa. Faça o seguinte:

1. Selecione uma célula na tabela onde deseja inserir o menu suspenso e clique em Developer > Controle de conteúdo da lista suspensa ícone, veja a captura de tela:

doc codificado por cores drop down 1

2. O menu suspenso é inserido na célula específica e clique em Developer > Propriedades, veja a captura de tela:

doc codificado por cores drop down 2

3. No Propriedades de controle de conteúdo caixa de diálogo, execute as seguintes operações:

(1.) Digite o nome do título no Título caixa de texto;

(2.) Clique Adicionar botão vá para o Adicionar Escolha diálogo;

(3.) No Adicionar Escolha caixa de diálogo, digite o item da lista suspensa no Nome visível caixa de texto.

doc codificado por cores drop down 3

4. Repita a Etapa 3 para inserir outros itens da lista suspensa conforme necessário.

5. Depois de criar a primeira lista suspensa, você pode copiá-la e colá-la em outras células conforme necessário. Veja a imagem:

doc codificado por cores drop down 4

6. Então você deve aplicar um código VBA, por favor, mantenha pressionado o ALT + F11 chaves para abrir o Microsoft Visual Basic para Aplicações janela.

7. No Microsoft Visual Basic para Aplicações janela, clique duplo Esse documento do Projeto-Projeto painel para abrir o modo e, em seguida, copie e cole o código a seguir no módulo em branco.

Código VBA: insira a lista suspensa codificada por cores na tabela de um documento do 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

doc codificado por cores drop down 5

Note: No código acima, Status é o nome do título ao criar a lista suspensa, e Preencha, Em Andamento, Não começar são os itens da lista suspensa, você pode alterá-los para o seu próprio. E você também pode alterar a cor de acordo com sua necessidade.

8. Em seguida, salve e feche a janela de código, agora, ao selecionar um item da lista suspensa, sua cor relativa será preenchida com a célula, veja a imagem:

doc drop down codificado por cores


 

Melhores ferramentas de produtividade de escritório

Kutools for Word - Eleve sua experiência com palavras com mais 100 Recursos notáveis!

🤖 Assistente de IA do Kutools: Transforme sua escrita com IA - Gerar conteúdo  /  Reescrever texto  /  Resumir documentos  /  Pergunte para obter informações com base no documento, tudo dentro do Word

📘 Domínio de documentos: Páginas divididas  /  Mesclar Documentos  /  Seleção de exportação em vários formatos (PDF/TXT/DOC/HTML...)  /  Conversão em lote para PDF  /  Exportar páginas como imagens  /  Imprima vários arquivos de uma vez...

Edição de conteúdo: Localização e substituição em lote em vários arquivos  /  Redimensionar todas as imagens  /  Transpor linhas e colunas da tabela  /  Converter tabela em texto...

🧹 Limpeza sem esforço: Varrer Espaços extras  /  Quebras de seção  /  Todos os cabeçalhos  /  Caixas de Texto  /  hiperlinks  / Para mais ferramentas de remoção, acesse nosso Remover Grupo...

Inserções criativas: Inserir Mil Separadores  /  Caixas de seleção  /  botões de rádio  /  QR Code  /  Código de barras  /  Tabela de linhas diagonais  /  Legenda da equação  /  Legenda da Imagem  /  Legenda da Tabela  /  Várias fotos  / Descubra mais no Inserir Grupo...

🔍 Seleções de precisão: Identificar páginas específicas  /  tabelas  /  formas  /  parágrafos de título  / Melhore a navegação com mais Selecione recursos...

Aprimoramentos de estrelas: Navegue rapidamente para qualquer local  /  inserir automaticamente texto repetitivo  /  alternar perfeitamente entre janelas de documentos  /  11 ferramentas de conversão...

👉 Quer experimentar esses recursos? Kutools para Word oferece um 60-day free trial, sem limitações! 🚀
 

 

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