Loncat ke daftar isi utama

Bagaimana cara memasukkan daftar drop-down kode warna dalam tabel Word?

Pengarang: Xiaoyang Terakhir Dimodifikasi: 2022-07-22

Misalkan, saya memiliki tabel di dokumen Word saya, dan sekarang, saya ingin memasukkan daftar drop-down kode warna ke dalam kolom tabel. Artinya ketika saya memilih satu opsi dari drop down, warna sel menjadi merah, dan ketika saya memilih opsi lain di drop down, warna sel menjadi hijau seperti gambar berikut yang ditampilkan. Bagaimana Anda bisa menyelesaikan pekerjaan ini di dokumen Word?

doc kode warna drop-down

Masukkan daftar drop-down kode warna dalam dokumen Word dengan kode VBA


Masukkan daftar drop-down kode warna dalam dokumen Word dengan kode VBA

Langkah-langkah berikut ini dapat membantu Anda menyelesaikan tugas ini sesuai kebutuhan, pertama, masukkan daftar drop-down, lalu terapkan warna untuk drop-down. Harap lakukan seperti ini:

1. Pilih sel di tabel tempat Anda ingin menyisipkan drop-down, lalu klik Pengembang > Kontrol Konten Daftar Drop-Down ikon, lihat tangkapan layar:

doc kode warna drop down 1

2. Drop down disisipkan ke dalam sel tertentu, lalu klik Pengembang > Properties, lihat tangkapan layar:

doc kode warna drop down 2

3. di Properti Kontrol Konten kotak dialog, lakukan operasi berikut:

(1.) Masukkan nama judul ke dalam Judul kolom tulisan;

(2.) Klik Add tombol pergi ke Tambahkan Pilihan dialog;

(3.) Di Tambahkan Pilihan dialog, ketik item daftar drop-down ke dalam Tampilan Nama kolom tulisan.

doc kode warna drop down 3

4. Ulangi Langkah 3 untuk memasukkan item daftar drop-down lainnya yang Anda butuhkan.

5. Setelah membuat daftar drop-down pertama, Anda dapat menyalin dan menempelkannya ke sel lain sesuai kebutuhan. Lihat tangkapan layar:

doc kode warna drop down 4

6. Maka Anda harus menerapkan kode VBA, harap tahan ALT + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

7. di Microsoft Visual Basic untuk Aplikasi jendela, klik dua kali Dokumen ini dari Proyek-Proyek panel untuk membuka mode, lalu salin dan tempel kode berikut ke dalam modul kosong.

Kode VBA: Masukkan daftar drop-down kode warna ke dalam tabel dokumen 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 kode warna drop down 5

Note: Pada kode di atas, Status adalah nama judul saat Anda membuat daftar drop-down, dan Menyelesaikan, Sedang Berlangsung, Tidak Mulai adalah item dari daftar drop-down, Anda dapat mengubahnya menjadi milik Anda. Dan Anda juga dapat mengubah warna sesuai kebutuhan Anda.

8. Kemudian simpan dan tutup jendela kode, sekarang, ketika Anda memilih satu item dari daftar drop-down, warna relatifnya akan diisi dengan sel, lihat tangkapan layar:

doc kode warna drop-down


 

Alat Produktivitas Kantor Terbaik

Kutools for Word - Tingkatkan Pengalaman Kata Anda dengan Over 100 Fitur Luar Biasa!

🤖 Asisten AI Kutools: Ubah tulisan Anda dengan AI - Hasilkan Konten  /  Menulis Ulang Teks  /  Meringkas Dokumen  /  Dapatkan Jawaban Cepat, semuanya dalam Word

📘 Penguasaan Dokumen: Halaman Terpisah  /  Gabungkan Dokumen  /  Ekspor Pilihan dalam Berbagai Format (PDF/TXT/DOC/HTML...)  /  Konversi Batch ke PDF  /  Ekspor Halaman sebagai Gambar  /  Cetak Banyak File sekaligus...

Pengeditan Isi: Temukan dan Ganti Batch di Banyak File  /  Ubah Ukuran Semua Gambar  /  Ubah Urutan Baris dan Kolom Tabel  /  Ubah Tabel menjadi Teks...

🧹 Bersih dengan Mudah: Menyapu Spasi Ekstra  /  Bagian Istirahat  /  Semua Header  /  Teks box  /  Hyperlink  / Untuk alat penghapus lainnya, kunjungi Hapus grup...

Sisipan Kreatif: Memasukkan Seribu Pemisah  /  Kotak Centang  /  Tombol Radio  /  Kode QR  /  barcode  /  Tabel Garis Diagonal  /  Keterangan Persamaan  /  Keterangan gambar  /  Keterangan Tabel  /  Banyak Gambar  / Temukan lebih lanjut di Sisipkan grup...

🔍 Pilihan Presisi: Tepat Halaman Tertentu  /  Meja  /  bentuk  /  Paragraf Judul  / Tingkatkan navigasi dengan lebih Pilih fitur...

Peningkatan Bintang: Navigasi ke Lokasi Mana Pun  /  Sisipkan Otomatis Teks Berulang  /  Beralih Antar Jendela Dokumen  /  11 Alat Konversi...

👉 Ingin mencoba fitur-fitur tersebut? Unduh Kutools for Word hari ini dan rasakan perbedaannya! 🚀
 

 

Comments (55)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
I tried applying the VBA code from this thread to a Word table with dropdown list and nothing happened.

I changed Status to the title of my table, Condition and changed Case to Snow, wet and Dry.

Any help would be appreciated.
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
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations