Consulting

Results 1 to 10 of 10

Thread: Listbox Content Control - Reset default?

  1. #1
    VBAX Regular
    Joined
    May 2012
    Posts
    22
    Location

    Listbox Content Control - Reset default?

    Let's say we have a list box. We have there a prompt "Pick value" and the options are "1", "2" and "3". User picks value "3". Now in order to reset this value to "Pick value", what do I need?

    This
        Dim obj
        Set obj = ActiveDocument.ContentControls(2)
        obj.Range.Text = obj.PlaceholderText.Value
    fails to "You are not allowed to edit this selection because it is protected".
    Last edited by KilpAr; 08-07-2017 at 03:33 PM.

  2. #2
    It would be better to select the control by name or tag, however

    Dim obj As ContentControl
        Set obj = ActiveDocument.ContentControls(2)
        obj.DropdownListEntries(1).Select
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    May 2012
    Posts
    22
    Location
    Quote Originally Posted by gmayor View Post
    It would be better to select the control by name or tag, however

    Dim obj As ContentControl
        Set obj = ActiveDocument.ContentControls(2)
        obj.DropdownListEntries(1).Select
    Ok, thanks, but this obviously only returns one of the entries, not the default/prompt.

  4. #4
    If the content control is inserted from the dialog, the default prompt is the first line.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    May 2012
    Posts
    22
    Location
    This works:

    With ActiveDocument.ContentControls(2)
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With

  6. #6
    Indeed it does - and the credit goes to Paul (Macropod) at http://www.msofficeforums.com/word-v...lt-prompt.html for coming up with this suggestion.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  7. #7
    VBAX Regular
    Joined
    May 2012
    Posts
    22
    Location
    Quote Originally Posted by gmayor View Post
    Indeed it does - and the credit goes to Paul (Macropod) for coming up with this suggestion.
    Yes, directly from his solution copy-paste.

  8. #8
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location

    Another option

    Quote Originally Posted by KilpAr View Post
    Yes, directly from his solution copy-paste.
    Yes, it is a great mystery why CCDDLs created with VBA are absent the first "Choose and item" default entry. Perhaps it was a smart guy or gal on the VBA side who realized the folly of leaving a "printed" field in a document that displays placeholder text.

    If you really want that "Choose and item" look you can create a buildingblock of the a basic CCDDL in your template and use:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 8/8/2017
    Dim oRng As Range
    Dim oCC As ContentControl
      'From a building block of a CCDDL created from the dialog.
      Set oRng = ActiveDocument.AttachedTemplate.BuildingBlockEntries("BuiltInCCDDL").Insert(Selection.Range, True)
      Set oCC = oRng.ContentControls(1)
      With oCC.DropdownListEntries
        .Add "A", "A"
        .Add "B", "B"
        .Add "C", "C"
      End With
      oCC.DropdownListEntries(1).Select
    lbl_Exit:
      Exit Sub
    End Sub
    For such CCs the oCC.DropdownListEntries(1).Select works to reset.
    Greg

    Visit my website: http://gregmaxey.com

  9. #9
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...lt-prompt.html
    Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  10. #10
    VBAX Regular
    Joined
    May 2012
    Posts
    22
    Location
    Yeah, should have included a link. I posted the answer here though as soon as I received an answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •