Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 01-17-2021, 07:21 PM
Guessed's Avatar
Guessed Guessed is offline Programatically create Fully Functional DropdownList (or ComboBox) Content Controls Windows 10 Programatically create Fully Functional DropdownList (or ComboBox) Content Controls Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg
I don't know where the error is coming from but interestingly, before the OOM error message shows, the code actually changes the list text value.
Code:
Sub AttemptSuccess3()
Dim oRng As Range
Dim oCC As ContentControl
  Set oRng = Selection.Range
  Application.CommandBars.ExecuteMso ("ContentControlDropDownList")
  oRng.End = oRng.End + 2
  Set oCC = oRng.ContentControls(1)
  With oCC
    .SetPlaceholderText , , "Select fruit"
    On Error Resume Next
      .DropdownListEntries.Item(1).Text = "Choose fruit from list."   'works anyway
    On Error GoTo 0
    .DropdownListEntries.Item(1).Value = ""
    .DropdownListEntries.Add "Apples", "Apples"
    .DropdownListEntries.Add "Blueberries", "Beets"
  End With
lbl_Exit:
  Exit Sub
End Sub
The other oddity I noticed is that you can't repeat the same line as you get an error message that says there is already a list item with that text value.
Code:
Sub AttemptSuccess4()
Dim oRng As Range
Dim oCC As ContentControl
  Set oRng = Selection.Range
  Application.CommandBars.ExecuteMso ("ContentControlDropDownList")
  oRng.End = oRng.End + 2
  Set oCC = oRng.ContentControls(1)
  With oCC
    .SetPlaceholderText , , "Select fruit"
    'Simply changing order of the following two lines seems to work and avoids the error.
    .DropdownListEntries.Item(1).Value = ""
    .DropdownListEntries.Item(1).Text = "Choose fruit from list."   'this works once
    .DropdownListEntries.Item(1).Text = "Choose fruit from list."   'errors if run a second time
    .DropdownListEntries.Add "Apples", "Apples"
    .DropdownListEntries.Add "Blueberries", "Beets"
    'Result: A fully functional DDL content control.
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to save docx to doc that checks compatibility and converts content controls to static content. staicumihai Word VBA 4 10-12-2016 08:23 PM
Programatically create Fully Functional DropdownList (or ComboBox) Content Controls Pass combobox content to header wpryan Word VBA 3 07-17-2015 01:44 AM
VBA ppt ComboBox behaivor: 1.OnFocus change value 2. get dropdownlist doesn't disappear after mousec janism22 PowerPoint 2 03-26-2015 12:35 AM
Create UserForm ComboBox or ContentControl ptmuldoon Word VBA 11 01-17-2015 05:58 PM
How to use the content of a combobox for {IF} field? Melaanie Word 0 06-14-2010 02:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:39 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