Skip i'r prif gynnwys

Sut i fewnosod rhestr ostwng cod lliw yn nhabl Word?

Gan dybio, mae gen i dabl yn fy nogfen Word, a nawr, rydw i eisiau mewnosod rhestr ostwng cod lliw mewn colofn o'r tabl. Mae'n golygu pan fyddaf yn dewis un opsiwn o'r gwymplen, mae lliw'r gell yn dod yn goch, a phan fyddaf yn dewis opsiwn arall yn y gwymplen, daw lliw'r gell yn wyrdd fel y dangosir y llun a ddangosir. Sut allech chi ddatrys y swydd hon yn nogfen Word?

cod lliw doc cod cwympo i lawr

Mewnosod rhestr ostwng cod lliw yn nogfen Word gyda chod VBA


Mewnosod rhestr ostwng cod lliw yn nogfen Word gyda chod VBA

Gall y camau canlynol eich helpu i orffen y dasg hon yn ôl yr angen, yn gyntaf, mewnosodwch y gwymplen, ac yna cymhwyso'r lliw ar gyfer y gwymplen. Gwnewch fel hyn:

1. Dewiswch gell yn y tabl lle rydych chi am fewnosod y gwymplen, ac yna cliciwch Datblygwr > Rheoli Cynnwys Rhestr Gollwng eicon, gweler y screenshot:

cod lliw cod doc gwympo 1

2. Mewnosodir y gwymplen yn y gell benodol, ac yna cliciwch Datblygwr > Eiddo, gweler y screenshot:

cod lliw cod doc gwympo 2

3. Yn y Priodweddau Rheoli Cynnwys blwch deialog, gwnewch y gweithrediadau canlynol:

(1.) Rhowch enw'r teitl yn y Teitl blwch testun;

(2.) Cliciwch Ychwanegu botwm ewch i'r Ychwanegu Dewis deialog;

(3.) Yn y Ychwanegu Dewis deialog, teipiwch yr eitem rhestr ostwng yn y arddangos Enw blwch testun.

cod lliw cod doc gwympo 3

4. Ailadroddwch Gam 3 i fewnosod eitemau rhestr ostwng eraill yn ôl yr angen.

5. Ar ôl creu'r gwymplen gyntaf, gallwch ei chopïo a'i gludo i gelloedd eraill yn ôl yr angen. Gweler y screenshot:

cod lliw cod doc gwympo 4

6. Yna dylech gymhwyso cod VBA, daliwch y ALT + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

7. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch ddwywaith Y Ddogfen hon oddi wrth y Prosiect-Prosiect cwarel i agor y modd, ac yna copïo a gludo'r cod canlynol i'r modiwl gwag.

Cod VBA: Mewnosodwch y gwymplen â chôd lliw yn nhabl dogfen 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

cod lliw cod doc gwympo 5

Nodyn: Yn y cod uchod, Statws yw'r enw teitl pan fyddwch chi'n creu'r gwymplen, a Cwblhau, Ar y gweill, Ddim yn Cychwyn yw eitemau'r gwymplen, gallwch eu newid i'ch un chi. A gallwch hefyd newid y lliw i'ch angen.

8. Yna arbedwch a chau ffenestr y cod, nawr, pan ddewiswch un eitem o'r gwymplen, bydd ei lliw cymharol yn cael ei llenwi â'r gell, gweler y screenshot:

cod lliw doc cod cwympo i lawr


 

Offer Cynhyrchiant Swyddfa Gorau

Kutools am Word - Dyrchafu Eich Profiad Word gyda Dros 100 Nodweddion Rhyfeddol!

🤖 Cynorthwy-ydd Kutools AI: Trawsnewidiwch eich ysgrifennu gydag AI - Cynhyrchu Cynnwys  /  Ailysgrifennu Testun  /  Crynhoi Dogfennau  /  Ymholwch am Wybodaeth yn seiliedig ar Ddogfen, i gyd o fewn Word

📘 Meistrolaeth Dogfen: Tudalennau Hollti  /  Uno Dogfennau  /  Dewis Allforio mewn Fformatau Amrywiol (PDF/TXT/DOC/HTML...)  /  Trosi swp i PDF  /  Allforio Tudalennau fel Delweddau  /  Argraffu Ffeiliau Lluosog ar unwaith...

Golygu Cynnwys: Swp Dod o Hyd i ac Amnewid ar draws Ffeiliau Lluosog  /  Newid Maint Pob Llun  /  Trawsosod Rhesi Bwrdd a Cholofnau  /  Trosi Tabl i Testun...

🧹 Ymdrech Glân: swap i ffwrdd Mannau Ychwanegol  /  Toriadau Adran  /  Pob Pennawd  /  Blychau Testun  /  hypergysylltiadau  / Am fwy o offer tynnu, ewch i'n Dileu Grŵp...

Mewnosodiadau Creadigol: mewnosod Mil o Wahanwyr  /  Blychau Gwirio  /  Botymau Radio  /  Cod QR  /  Cod Bar  /  Tabl Llinell Lletraws  /  Pennawd Hafaliad  /  Capsiwn Delwedd  /  Pennawd Tabl  /  Lluniau Lluosog  / Darganfod mwy yn y Mewnosod Grŵp...

🔍 Detholiadau Manwl: pinbwynt tudalennau penodol  /  tablau  /  siapiau  /  paragraffau pennawd  / Gwella llywio gyda mwy Dewiswch nodweddion...

Gwelliannau Seren: Llywiwch yn gyflym i unrhyw leoliad  /  auto-mewnosod testun ailadroddus  /  toglo'n ddi-dor rhwng ffenestri dogfennau  /  11 Offer Trosi...

???? Eisiau rhoi cynnig ar y nodweddion hyn? Mae Kutools ar gyfer Word yn cynnig a Treial am ddim 60-dydd, heb unrhyw gyfyngiadau! 🚀
 

 

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