Search code examples
vbavba7word-automationword-contentcontrol

How to get the VBA code auto select fields from Content Control drop down options


I wish to auto populate value from content control drop down option. I have four options in the drop down list and I want option 1 to be populated for Case Methodology.

While trying the below code is giving me:

VBA 6124 error- You can not edit it because it is protected,

Code:

Select Case oCC.Title
            Case "Methodology"
                oCC.Range.Text = " abc"
            Case "Methodology2"
                oCC.Range.Text = "NA"

I tried .LockContents=False but it is not working either. How can I write the code that can autoselect first value from the four options?


Solution

  • As this is a dropdown content control, Range.Text is read-only.

    You have to use:

    oCC.DropdownListEntries(2).Select
    

    2 because usually the placeholder text is the first in your list.