Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-10-2021, 08:41 AM
gmaxey gmaxey 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
Programatically create Fully Functional DropdownList (or ComboBox) Content Controls
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default Programatically create Fully Functional DropdownList (or ComboBox) Content Controls

Has anyone had any success (without using a sledgehammer) for creating and insert fully functional dropdown list contentcontrols?

A basic attempt (Attempt 1) produces a CC with the expected "Choose an item." displayed. But there is no "Choose an item." DD list entry, so no way for the user to re-select the null a null listing.

Code:
Sub Attempt1()
Dim oCC As ContentControl
  Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList, Selection.Range)
  With oCC
    .DropdownListEntries.Add "A", "Apples"
    .DropdownListEntries.Add "B", "Beets"
  End With
  'Result: "Choose an item." is displayed but there is no null "Choose an item." entry in the resulting DD List.
lbl_Exit:
  Exit Sub
End Sub
With a little more grease, (Attempt 2) produces a CC with the expected "Choose an item." displayed and the expected "Choose an item." DD list entry, but if that entry is selected, the value displayed is the "text" variant of "Choose and item." not the expected null variant.


Code:
Sub Attempt2()
Dim oCC As ContentControl
  Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList, Selection.Range)
  With oCC
    .DropdownListEntries.Add oCC.PlaceholderText, vbNullString
    .DropdownListEntries.Add "A", "Apples"
    .DropdownListEntries.Add "B", "Beets"
    'Result: "Choose an item." is displayed and there is a "Choose a item." in the DD List. _
    However, if that item is selected, the display is not displayed as null Placeholder text."
  End With
lbl_Exit:
  Exit Sub
End Sub
Now the sledgehammer. With (Attempt3), I first created a basic DDL content control with the built-in interface and saved it as a buildingblock. This works of course but requires access to a template.

Code:
Sub Attempt3()
Dim oRng As Range
Dim oCC As ContentControl
  'Requires a DDL inserted via built-in UI saved as a buildingblock entry.
  Set oRng = Selection.Range
  ThisDocument.AttachedTemplate.BuildingBlockEntries("BasicDDL").Insert oRng, True
  oRng.End = oRng.End + 2
  Set oCC = oRng.ContentControls(1)
  With oCC
    .DropdownListEntries.Add "A", "Apples"
    .DropdownListEntries.Add "B", "Beets"
    'Result: A fully functional DDL content control.
  End With
lbl_Exit:
  Exit Sub
End Sub
Has anyone found a way to do this without having to use the built-in UI or a template?


Cross posted at:


Programatically create Fully Funcitional DropdownList (or ComboBox) Content Controls
Programatically create Fully Funcitional DropdownList (or - Microsoft Community
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by macropod; 01-10-2021 at 02:21 PM. Reason: Added code tags
Reply With Quote
 



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 06:18 PM.


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