Bỏ qua nội dung chính

Làm thế nào để chèn danh sách thả xuống được mã hóa màu trong bảng Word?

Tác giả: Tiểu Dương Sửa đổi lần cuối: 2022-07-22

Giả sử, tôi có một bảng trong tài liệu Word của mình và bây giờ, tôi muốn chèn danh sách thả xuống được mã hóa màu vào một cột của bảng. Điều đó có nghĩa là khi tôi chọn một tùy chọn từ menu thả xuống, màu ô sẽ trở thành màu đỏ và khi tôi chọn một tùy chọn khác trong menu thả xuống, màu ô sẽ trở thành màu xanh lục như hình minh họa sau. Làm thế nào bạn có thể giải quyết công việc này trong tài liệu Word?

màu doc ​​được mã hóa thả xuống

Chèn danh sách thả xuống được mã hóa màu trong tài liệu Word với mã VBA


Chèn danh sách thả xuống được mã hóa màu trong tài liệu Word với mã VBA

Các bước sau có thể giúp bạn hoàn thành tác vụ này khi cần, trước tiên, hãy chèn danh sách thả xuống, sau đó áp dụng màu cho danh sách thả xuống. Vui lòng làm như sau:

1. Chọn một ô trong bảng mà bạn muốn chèn trình đơn thả xuống, sau đó bấm Nhà phát triển > Kiểm soát nội dung danh sách thả xuống biểu tượng, xem ảnh chụp màn hình:

màu doc ​​được mã hóa thả xuống 1

2. Trình đơn thả xuống được chèn vào ô cụ thể, sau đó nhấp vào Nhà phát triển > Bất động sản, xem ảnh chụp màn hình:

màu doc ​​được mã hóa thả xuống 2

3. Trong Thuộc tính kiểm soát nội dung hộp thoại, vui lòng thực hiện các thao tác sau:

(1.) Nhập tên tiêu đề vào Yêu sách hộp văn bản;

(2.) Nhấp vào Thêm nút đi đến Thêm lựa chọn hộp thoại;

(3.) Trong Thêm lựa chọn , nhập mục danh sách thả xuống vào Tên hiển thị hộp văn bản.

màu doc ​​được mã hóa thả xuống 3

4. Lặp lại Bước 3 để chèn các mục danh sách thả xuống khác khi bạn cần.

5. Sau khi tạo danh sách thả xuống đầu tiên, bạn có thể sao chép và dán nó vào các ô khác khi cần. Xem ảnh chụp màn hình:

màu doc ​​được mã hóa thả xuống 4

6. Sau đó, bạn nên áp dụng mã VBA, vui lòng giữ ALT + F11 phím để mở Microsoft Visual Basic cho các ứng dụng cửa sổ.

7. Trong Microsoft Visual Basic cho các ứng dụng cửa sổ, nhấp đúp Tài liệu này từ Dự án-Dự án để mở chế độ, sau đó sao chép và dán mã sau vào mô-đun trống.

Mã VBA: Chèn danh sách thả xuống được mã hóa màu vào bảng của tài liệu 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

màu doc ​​được mã hóa thả xuống 5

Chú thích: Trong đoạn mã trên, Trạng thái là tên tiêu đề khi bạn tạo danh sách thả xuống và Hoàn thành, Đang diễn ra, Không bắt đầu là các mục của danh sách thả xuống, bạn có thể thay đổi chúng thành của riêng bạn. Và bạn cũng có thể thay đổi màu sắc theo nhu cầu của bạn.

8. Sau đó, lưu và đóng cửa sổ mã, bây giờ, khi bạn chọn một mục từ danh sách thả xuống, màu tương đối của nó sẽ được tô đầy ô, xem ảnh chụp màn hình:

màu doc ​​được mã hóa thả xuống


 

Công cụ năng suất văn phòng tốt nhất

Kutools cho Word - Nâng cao trải nghiệm sử dụng từ của bạn với Over 100 Các tính năng đáng chú ý!

🤖 Trợ lý AI của Kutools: Biến đổi bài viết của bạn bằng AI - Tạo nội dung  /  Viết lại văn bản  /  Tóm tắt tài liệu  /  Hỏi thông tin dựa trên tài liệu, tất cả đều có trong Word

📘 Làm chủ tài liệu: Chia trang  /  Hợp nhất tài liệu  /  Lựa chọn xuất khẩu ở nhiều định dạng khác nhau (PDF/TXT/DOC/HTML...)  /  Chuyển đổi hàng loạt sang PDF  /  Xuất trang dưới dạng hình ảnh  /  In nhiều tập tin cùng một lúchữu ích. Cảm ơn !

Chỉnh sửa nội dung: Tìm và thay thế hàng loạt trên nhiều tệp  /  Thay đổi kích thước tất cả hình ảnh  /  Hoán đổi hàng và cột của bảng  /  Chuyển bảng thành văn bảnhữu ích. Cảm ơn !

🧹 Dễ dàng làm sạch: Quét đi Không gian bổ sung  /  Phần ngắt  /  Tất cả các tiêu đề  /  Hộp văn bản  /  Các siêu liên kết  / Để biết thêm các công cụ xóa, hãy truy cập Xóa nhómhữu ích. Cảm ơn !

Phụ trang quảng cáo: Chèn Ngàn dấu phân cách  /  Hộp kiểm tra  /  Nút radio  /  Mã QR  /  Mã vạch  /  Bảng đường chéo  /  Chú thích phương trình  /  Hình ảnh Caption  /  Bảng chú thích  /  Nhiều Hình Ảnh  / Khám phá thêm trong Chèn nhómhữu ích. Cảm ơn !

???? Lựa chọn chính xác: Xác định trang cụ thể  /  bảng  /  hình dạng  /  đoạn văn tiêu đề  / Tăng cường điều hướng với chi tiết Chọn tính nănghữu ích. Cảm ơn !

Cải tiến sao: Điều hướng nhanh chóng đến bất kỳ vị trí nào  /  tự động chèn văn bản lặp đi lặp lại  /  chuyển đổi liền mạch giữa các cửa sổ tài liệu  /  11 công cụ chuyển đổihữu ích. Cảm ơn !

👉 Bạn muốn thử những tính năng này? Kutools cho Word cung cấp một 60 ngày dùng thử miễn phí, không có giới hạn! 🚀
 

 

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