Namig: drugi jeziki so prevedeni v Google. Lahko obiščete English različico te povezave.
Vpiši se
x
or
x
x
Registracija
x

or

Kako ustvariti odvisne spustne sezname v Wordovem dokumentu?


Kot je prikazano levo sliko, morate omejiti izbire na drugem spustnem seznamu glede na možnost v prvem spustnem meniju, kako lahko storite? V tem članku se prikaže način ustvarjanja odvisnih spustnih seznamov v dokumentu Word.

Ustvari odvisne spustne sezname v Wordu s kodo VBA


Ustvari odvisne spustne sezname v Wordu s kodo VBA

Spodnja koda VBA vam lahko pomaga ustvariti odvisne spustne sezname v dokumentu Word. Prosimo, sledite navodilom korak za korakom.

1. Prvič, v dokument Word morate vstaviti dva spustna seznama. Kliknite Razvojni > Legacy Forms > Polje padajoče oblike. Prikaz slike:

2. Z desno tipko kliknite prvi spustni seznam (ta spustni seznam naj bo starševski) in kliknite Lastnosti. Prikaz slike:

3. V odprtju Možnosti polja za spustni obrazec pogovorno okno, morate:

3.1 Vnesite kategorijo v Spustni element polje in nato kliknite Dodaj ponovite postopek, dokler se v polje Spiski v spustnem seznamu ne dodajo vse kategorije.

3.2 Vnesite ddfood v zaznamek škatla.

3.3 Kliknite na OK gumb. Prikaz slike:

4. Z desno tipko kliknite drugi spustni seznam, kliknite Nepremičnine odprl svoj Možnosti polja za spustni obrazec pogovorno okno in v pogovornem oknu vnesite ddKategorija v zaznamek polje in kliknite na OK gumb. Prikaz slike:

5. Pritisnite druga + F11 tipke za odpiranje Microsoft Visual Basic za aplikacije okno.

6. V Ljubljani Microsoft Visual Basic za aplikacije okno, kliknite Vstavi > Modul, nato kopirajte pod kodo VBA v okno Modul.

VBA koda: ustvarite odvisni spustni seznam v Wordu

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

Opombe:

1. V kodi prosimo spremenite postavke v vsakem primeru, kot jih potrebujete.

2. ddfood in ddKategorija se morajo ujemati z možnostmi zaznamka, ki ste jih vnesli v zgornja dva Možnosti polja za spustni obrazec pogovorna okna.

7. Shranite kodo in se vrnite v dokument.

8. Desni klik na prvi spustni seznam in kliknite Nepremičnine da odprete Možnosti polja za spustni obrazec pogovorno okno. V pogovornem oknu izberite zgornje ime makra (tukaj je Popolateddfood) iz Izhod spustni seznam in nato kliknite OK gumb.

9. Zdaj kliknite Razvojni > Omeji urejanje kot je prikazano spodaj.

10. V Ljubljani Omeji urejanje podokno, morate:

10.1), Preverite Dovoli samo to vrsto urejanja v dokumentu škatla;

10.2) Izberite Polnjenje obrazcev možnost s spustnega seznama;

10.3) Kliknite na Da, začnite uveljavljati zaščito gumb;

10.4) V Začnite uveljavljati zaščito pogovorno okno, vnesite geslo in kliknite OK gumb. Prikaz slike:

Zdaj so ustvarjeni odvisni spustni seznami. Ko izberete Fruit s prvega spustnega seznama, se lahko izberejo le kategorije sadja v drugem.

Priporočena orodja za produktivnost Worda

shot kutools beseda kutools zavihek 1180x121
shot kutools beseda kutools plus zavihek 1180x120

Kutools for Word - več kot 100 napredne funkcije Za Microsoft Word shranite svoj čas 50%

  • Zapletene in ponavljajoče se operacije lahko opravite enkratno obdelavo v sekundah.
  • V dokument Worda vstavite več slik v mapah.
  • Združite in združite več datotek Word v mapah v eno z želenim naročilom.
  • Razdelite trenutni dokument v ločene dokumente v skladu z naslovom 1, odlomkom odseka ali drugimi merili.
  • Pretvorite datoteke med Doc in Docx, Docx in PDF, zbirko orodij za običajne konverzije in izbiro, in tako naprej...
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Paul · 10 days ago
    Hi,

    How do we text wrap? I followed the step and it works fine except that when the second list is too long, it goes beyond the page. Is there a way to have it automatically wrap?
  • To post as a guest, your comment is unpublished.
    Marc · 1 months ago
    Hi There,
    are there restrictions with the name in the field (e.g. 2 words, or use of special caracters)?
    Like Field A (Company Name) Field B (Director Name, like Jack Black).
    Thanks!
  • To post as a guest, your comment is unpublished.
    mary · 3 months ago
    can this be done in older versions of Word or have to be saved as a certain doc type?
  • To post as a guest, your comment is unpublished.
    Ingrid · 3 months ago
    Can you add this to multiple areas on a single page consisting of multiple sections? I was able to successfully complete the process in one section of my document, but when I attempt to complete the same process while on the same page, but in a different section of my document and with new drop down options, only my first added boxes are working, not the ones in the second section..
    • To post as a guest, your comment is unpublished.
      crystal · 2 months ago
      Hi ingrid,
      Supposing you have three groups of dependent drop-down lists in your document. If you need all dependent drop-down lists take effect, please apply the below VBA code and do the below settings:

      In the step 4 and 5 we mentioned in the article, now you need to do the following changes:
      1. For the first group of the dependent drop-down lists, please get into each drop-down list's Properties window and specify the Bookmark as ddfood1 and ddCategory1 separately;
      2. For the second group of the dependent drop-down lists, please get into each drop-down list's Properties window and specify the Bookmark as ddfood2 and ddCategory2 separately;
      2. For the third group of the dependent drop-down lists, please get into each drop-down list's Properties window and specify the Bookmark as ddfood3 and ddCategory3 separately;

      Then go ahead exactly as we provided in the article to finish the whole settings.

      VBA code:
      Sub Populateddfood()
      'Update by Extendoffice 2019/03/18
      Dim xDirection As FormField
      Dim xState As FormField
      Dim xRng As Range
      Dim xFoodBM, xCategoryBM As String
      Set xRng = Selection.Range
      On Error Resume Next
      For i = 1 To ActiveDocument.FormFields.Count
      xFoodBM = "ddfood" & i
      xCategoryBM = "ddCategory" & i
      Set xDirection = ActiveDocument.FormFields(xFoodBM)
      Set xState = ActiveDocument.FormFields(xCategoryBM)
      If (Not (xState Is Nothing)) And (Not (xDirection Is Nothing)) Then
      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 If
      Set xDirection = Nothing
      Set xState = Nothing
      Next
      xRng.Select
      End Sub
  • To post as a guest, your comment is unpublished.
    MM · 4 months ago
    Is there a similar code to do the almost the exact same thing except have a text form field automatically populate depending upon the dropdown choice? For example, choosing a specific company in the dropdown and having a text form field automatically populate with the city where the company is located?
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Good day,
      Sorry can help you with that. Thank you for your comment.