+ Reply to Thread
Results 1 to 10 of 10

ContentControl Listbox - Get selected "Value" instead of "Display Text"

  1. #1
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    ContentControl Listbox - Get selected "Value" instead of "Display Text"

    2 values are set up for each Listbox list item
    - Display text
    - Value
    The value displayed for user selection is "Display Text", and after selection it is also the "Display Text"

    My macro also extracts the selected "Display Text", but I want the other "value" (see the picture)
    What is the correct syntax to use to get at the other value?

    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    See, for example: http://www.msofficeforums.com/word-v...html#post46903
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Hey Paul,

    I'd actually reviewed that thread linked above earlier and from it I couldn't manage to cull out the reference to how we address the VALUE content of the selected dropdown selection.

    Can you please address that specifically here, just the relevant sample code snippet that addresses that field? Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Quote Originally Posted by JBeaucaire View Post
    I'd actually reviewed that thread linked above earlier and from it I couldn't manage to cull out the reference to how we address the VALUE content of the selected dropdown selection.

    Can you please address that specifically here, just the relevant sample code snippet that addresses that field? Thanks.
    In the link, the macro extracts the content control value via:
    .DropdownListEntries(i).Value
    To get i from a selected entry, though, you have to loop through the DropdownListEntries to find which one matches the displayed entry (i.e. .Range.Text).

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Macropod, as per forum rules, we need to present simple ideas right here in the thread rather than links to other threads where the answer is buried somewhere. Links to other places, when used, need to be to the exact location of the exact answer for the question being posed. And the simple answer should still be posted here in the original thread 99% of the time, even with an external link for additional reading.

    Thanks for clarifying, I would never have figured that out! So the short answer is: "There's no way to read the value from the current selection, only from the original DropDownListEntries. As such, you must loop through them all until you find the one currently selected."

    This worked for me:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-26-2017 at 08:00 PM.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Thanks @JBeaucaire and @macropod
    Excellent - works for me too.

    One final question - is there a way to get this "value" into a word document without using VBA?
    If there is - how?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Your two choices are

    1) open the ContentControls manually and copy them out by eye
    2) use the loop technique shown above to iterate through them and write them out.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Your two choices are

    1) open the ContentControls manually and copy them out by eye
    2) use the loop technique shown above to iterate through them and write them out.

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    @JBeaucaire I will not be taking up option1 - I have not learnt to type with my eye
    Last edited by kev_; 01-27-2017 at 01:32 PM.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: ContentControl Listbox - Get selected "Value" instead of "Display Text"

    Hehe, can't believe I typo'd that, will leave it there as a badge of lame

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. Display "TEXT" in "Values" field in PIVOT TABLE using VBA!!
    By meus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2015, 09:56 AM
  3. Display "TEXT" in "Values" field in PIVOT TABLE using VBA!!
    By meus in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-04-2015, 06:14 AM
  4. Replies: 1
    Last Post: 08-15-2014, 06:00 AM
  5. Replies: 0
    Last Post: 03-21-2014, 09:58 AM
  6. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  7. How can i copy value from "HTMLText"(EMBED("Forms.HTML:Text","")),using Macro
    By andrewyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2010, 12:47 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1