Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-14-2022, 05:49 AM
LustNik LustNik is offline Dropdown list dependency and autofill Windows 10 Dropdown list dependency and autofill Office 2021
Novice
Dropdown list dependency and autofill
 
Join Date: Mar 2022
Posts: 7
LustNik is on a distinguished road
Default Dropdown list dependency and autofill

Hi

Pretty new to advanced functions in Word, and complete beginner in the world of VBA.

Im trying to create a dropdown list with a secondary, dependent dropdown. First has 2 options: "yes" or "no". In case of "yes", 3 options are presented in the secondary list which will change color according to answer. So far so good!



However, when the "no" option is selected, I would like the secondary dropdown to autofill something along the lines of "N/A" or "—".

None of my attempts at the trusted copy/paste method has worked, so the code below is what I have that works.

Thanks in advance!

Code:
Option Explicit
Dim StrOption As String
Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
If CCtrl.Title = "Relevans" Then StrOption = CCtrl.Range.Text
End Sub

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long, StrOut As String
With CCtrl
  If .Title = "Relevans" Then
    If StrOption = .Range.Text Then Exit Sub
    Select Case .Range.Text
      Case "Ja"
        StrOut = "Uakseptabel,Middels,Akseptabel"
      Case "Nei"
        StrOut = "—"
      Case Else
        .Type = wdContentControlText
        .Range.Text = ""
        .Type = wdContentControlDropdownList
    End Select
    With ActiveDocument.SelectContentControlsByTitle("Risiko")(1)
      .DropdownListEntries.Clear
      For i = 0 To UBound(Split(StrOut, ","))
        .DropdownListEntries.Add Split(StrOut, ",")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
  End If
End With

With CCtrl.Range
    If CCtrl.Title = "Risiko" Then
        Select Case .Text
            Case "Uakseptabel"
                .Cells(1).Shading.BackgroundPatternColor = RGB(255, 0, 0)
            Case "Akseptabel"
                .Cells(1).Shading.BackgroundPatternColor = RGB(0, 176, 80)
            Case "Middels"
                .Cells(1).Shading.BackgroundPatternColor = RGB(255, 255, 0)
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill Dropdown Syed Rashid Word 1 06-22-2021 10:59 AM
Compose Email - Autofill List Style Change RoscoW88 Outlook 2 05-24-2021 06:44 PM
Dropdown list dependency and autofill Autofill a field based on drop down list selection lascough20 Word 2 09-21-2018 02:24 AM
Selection of a dropdown creates another dropdown wih the list krishnamurthy.ka2810 Word VBA 1 04-26-2018 11:44 PM
Dropdown list dependency and autofill Autofill a form which is contingent on a dropdown selection. biffle0764 Word 2 05-09-2012 12:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft