メインコンテンツへスキップ

Word文書で依存ドロップダウンリストを作成するにはどうすればよいですか?


左のスクリーンショットが示すように、最初のドロップダウンのオプションに基づいて、XNUMX番目のドロップダウンリストの選択肢を制限する必要があります。どうすればよいですか? この記事では、Word文書に依存ドロップダウンリストを作成する方法を紹介します。

VBAコードを使用してWordで依存ドロップダウンリストを作成する


VBAコードを使用してWordで依存ドロップダウンリストを作成する

以下のVBAコードは、Word文書に依存するドロップダウンリストを作成するのに役立ちます。 手順に従って手順に従ってください。

1.まず、Word文書にXNUMXつのドロップダウンリストを挿入する必要があります。 クリック Developer > レガシーフォーム > ドロップダウンフォームフィールド。 スクリーンショットを参照してください:

2.最初のドロップダウンリスト(このドロップダウンリストは親リストである必要があります)を右クリックし、[ プロパティ。 スクリーンショットを参照してください:

3.オープニングで ドロップダウンフォームフィールドオプション ダイアログボックスでは、次のことを行う必要があります。

3.1カテゴリをに入力します ドロップダウンアイテム ボックスをクリックし、 Add ボタンをクリックし、すべてのカテゴリがドロップダウンリストボックスのアイテムに追加されるまで操作を繰り返します。

3.2入力 DDフードブックマーク ボックス。

3.3 OK ボタン。 スクリーンショットを参照してください:

4. XNUMX番目のドロップダウンリストを右クリックし、をクリックします プロパティ そのオープンする ドロップダウンフォームフィールドオプション ダイアログボックスで、ダイアログに次のように入力します ddカテゴリーブックマーク ボックスをクリックして OK ボタン。 スクリーンショットを参照してください:

5。 プレス 他の + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

6。 の中に アプリケーション向け Microsoft Visual Basic ウィンドウ、クリック インセット > モジュール、 次に、以下のVBAコードをモジュールウィンドウにコピーします。

VBAコード:Wordで依存ドロップダウンリストを作成する

Sub Populateddfood()
'Update by Extendoffice 2018/10/25
    Dim xDirection As FormField
    Dim xState As FormField
    On Error Resume Next
    Set xDirection = ActiveDocument.FormFields("ddfood")
    Set xState = ActiveDocument.FormFields("ddCategory")
    If ((xDirection Is Nothing) Or (xState Is Nothing)) Then Exit Sub
    With xState.DropDown.ListEntries
        .Clear
        Select Case xDirection.Result
            Case "Fruit"
                .Add "Apple"
                .Add "Banana"
                .Add "Peach"
                .Add "Lychee"
                .Add "Watermelon"
            Case "Vegetable"
                .Add "Cabbage"
                .Add "Onion"
            Case "Meat"
                .Add "Pork"
                .Add "Beef"
                .Add "Mutton"
        End Select
    End With
End Sub

注意:

1.コードでは、必要に応じてそれぞれの場合の項目を変更してください。

2. DDフード & ddカテゴリー 上記のXNUMXつで入力したブックマークオプションと一致する必要があります ドロップダウンフォームフィールドオプション ダイアログボックス。

7.コードを保存して、ドキュメントに戻ります。

8.最初のドロップダウンリストを右クリックして、 プロパティ を開く ドロップダウンフォームフィールドオプション ダイアログボックス。 ダイアログボックスで、上記のマクロ名(ここではPopolateddfood)を選択してください。 出口 ドロップダウンリストをクリックし、 OK

9.次にクリックします Developer > 編集を制限する 以下のスクリーンショットのように。

10。 の中に 編集を制限する ペイン、次のことを行う必要があります。

10.1)確認してください このタイプの編集のみを許可する ドキュメント内 ボックス;

10.2)選択 フォームへの記入 ドロップダウンリストのオプション。

10.3)をクリックします はい、保護の実施を開始します ボタン;

10.4) 保護の実施を開始します ダイアログで、パスワードを入力し、をクリックします OK ボタン。 スクリーンショットを参照してください:

これで、依存するドロップダウンリストが作成されます。 最初のドロップダウンリストでフルーツを選択すると、XNUMX番目のドロップダウンリストではフルーツカテゴリのみを選択できます。

最高のオフィス生産性向上ツール

Kutools for Word - Over で単語体験を向上させましょう 100 注目すべき機能!

🤖 Kutools AI アシスタント: AI であなたの文章を変革します - コンテンツを生成する  /  テキストを書き換える  /  文書を要約する  /  情報のお問い合わせ 文書に基づいて、すべて Word 内で

📘 ドキュメントマスタリー: 分割ページ  /  ドキュメントをマージする  /  選択内容をさまざまな形式でエクスポート (PDF/TXT/DOC/HTML...)  /  PDFへの一括変換  /  ページを画像としてエクスポート  /  複数のファイルを一度に印刷する...

コンテンツ編集: バッチ検索と置換 複数のファイルにわたる  /  すべての画像のサイズを変更する  /  テーブルの行と列を転置する  /  表をテキストに変換...

🧹 楽にお掃除:振り払って 余分なスペース  /  セクションブレーク  /  すべてのヘッダー  /  テキストボックス  /  ハイパーリンク  / その​​他の取り外しツールについては、当社の Web サイトをご覧ください。 グループを削除...

クリエイティブインサート:挿入 千の区切り文字  /  チェックボックス  /  ラジオボタン  /  QRコード  /  バーコード  /  斜線テーブル  /  方程式のキャプション  /  画像キャプション  /  テーブルキャプション  /  複数の写真  / 詳細については、 グループを挿入...

🔍 正確な選択: ピンポイント 特定のページ  /  テーブル  /  シェイプ  /  見出し段落  / ナビゲーションを強化する 他には? 機能の選択...

スターの強化: あらゆる場所に素早く移動  /  繰り返しのテキストを自動挿入  /  ドキュメントウィンドウをシームレスに切り替える  /  11 変換ツール...

👉 これらの機能を試してみませんか? Kutools for Wordは、 60日無料トライアル、制限なし! 🚀
 
Comments (32)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi there,

I have managed to follow the steps, thanks for your help.

I can't find my code when pressing Alt+F11 though? My drop downs are still there but I can't find the back coding?
This comment was minimized by the moderator on the site
Hi Crystal, thanks for the tutorial, it was useful and well written. Is it possible to add a third dropdown list with options that change depending on what is selected from the second dropdown list?
This comment was minimized by the moderator on the site
Hi Jack,

You can add a third drop-down list with options that change depending on what is selected from the second drop-down list. But you need to insert another "Drop-Down Form Field" and a new VBA code in advance.
1. Follow the steps from 1 to 4 in the post to create the first and second drop-down list and modify the properties.
2. Insert the third Drop-Down Form Field, double click to open it's Properties dialog box, enter a name in the Bookmark textbox (the same as the operation for the first and second drop-down lists) , in this case, I made up a random name called ddTaste, and then click OK.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/word-drop-down1.png
3. Open the Microsoft Visual Basic for Applications window, enter the VBA code provided in the article into the Module1. Then insert a new Module (called Module2), copy and paste the following VBA code into this Module2.
VBA code: Use for the third dependent drop-down list

Sub PopulateddTaste()
Select Case ActiveDocument.FormFields("ddCategory").Result
Case "Apple"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "AA"
.Add "BB"
End With
Case "Banana"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "CC"
.Add "DD"
End With
Case "Peach"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "EE"
.Add "FF"
End With
Case "Lychee"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "GG"
.Add "HH"
End With
Case "Watermelon"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "II"
.Add "JJ"
End With
Case "Cabbage"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "LL"
.Add "MM"
End With
Case "Onion"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "OO"
.Add "PP"
End With
Case "Pork"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "QQ"
.Add "RR"
End With
Case "Beef"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "SS"
.Add "TT"
End With
Case "Mutton"
With ActiveDocument.FormFields("ddTaste").DropDown.ListEntries
.Clear
.Add "UU"
.Add "VV"
End With
End Select
End Sub

Note: In the code, AA, BB, CC... are the items you want to show in the third drop-down list, based on what was selected from the second drop-down list. For example, when you select "Apple" in the second drop-down, the third drop-down list will display the items AA and BB. Please modify this items to meet your needs.
4. Save the code and go back to the document. Follow the step 8 in the article to specify the macro for the first drop-down.
5. Double click the second drop-down list, choose "PopulateddTaste" in the Exist drop-down list.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/word-drop-down2.png
6. Then follow the step 8 to restrict editing in this document.
Now you have create a three level drop-down list.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/word-drop-down3.gif
This comment was minimized by the moderator on the site
Thanks for getting back to me, your time and help is appreciated.
This comment was minimized by the moderator on the site
Hallo,

ist das ganze auch unter Outlook möglich. Leider bekomme ich das so nicht hin da die Eigenschaften des Dropdown Menüs ganz anders aussehen.

Ich wollte unter Aufgaben einen Reparaturauftrag erstellen wo man Gebäude,Bereich und dan Zimmernummer oder Bezeichnung auwählen kann.

Ist das möglich in Outlook/Aufgaben?



Danke
This comment was minimized by the moderator on the site
Hi,
You can create a drop-down list with custom field in Outlook Task window by following the steps in this article:
How To Add A Drop Down List With Custom Filed In Outlook Task Window?
https://www.extendoffice.com/documents/outlook/4453-outlook-custom-fields-tasks-drop-down.html
Or create a drop-down list in word then copy and paste it into the Task window as you need.
But if you want to create dependent drop-down lists in Outlook Task, no method has been found yet.
Sorry about that.
This comment was minimized by the moderator on the site
Hi, many thx for the detailed tutorial, but I have a question since the word template is for others' use. You mentioned protecting mode and a password is a must, this can do if I tell them the password, then there is a conflict: there are some other blanks which are needed to be filled in, this cannot be done only if the protecting mode is off. What should I do? Is there any method to meet both 2 needs?
This comment was minimized by the moderator on the site
Hi, thx for the detailed tutorial, but I have a question since the word template is for others' use, 
This comment was minimized by the moderator on the site
This was extremely helpful, thank you.
I have a question, is there a way to modify the code so that when I select a new item from the first drop-down list, the dependent one will clear up?
This comment was minimized by the moderator on the site
Sorry for the late reply, only stumbled upon this page today :-)
It already does that. The first statement inside the Select case ... End select construction clears the second list. If none of the criteria are met, nothing is added.
This comment was minimized by the moderator on the site
Hello, for some reason I cannot modify anything else in the word file if the drop down list is active. Is there a way to avoid that?

Thank you
This comment was minimized by the moderator on the site
I have the same issue has anyone been able to help on this one
This comment was minimized by the moderator on the site
سلام من همه مراحل رو رفتم ولی درآخر وقتی از لیست اول یه استان رو انتخاب می کنم تویه لیست دوم فقط شهر های اون استان رو نمیاره
چیکار باید بکنم؟
This comment was minimized by the moderator on the site
I am using this same code however the text that I replacing the ddcategory with has 100 plus words. Is there anyway to wrap the text to prevent it from going off of the page and disappearing?
This comment was minimized by the moderator on the site
I have the same problem!! :0
This comment was minimized by the moderator on the site
Thank you for this very useful resource.

Is it possible to repeat the same dependent drop down multiple times within a form?

I need the form filler to assign a category to each new row (but with the same options each time).I have successfully created the drop downs but when I restrict editing to test they seem to reset themselves as I work down the rows.

Thanks
Amy
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