Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    46
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Set the colors of drop down menu entries

    I use such a code to create drop down entries:
    Code:
    Set DRP_obj = Selection.Range.ContentControls.Add(wdContentControlDropdownList)
     With DRP_obj.DropdownListEntries
            .Add p1
            .Add p2
            .Add p3
     End With
    Can I:
    1- Set the color that the "choose an item" appears
    2- Set the color (different) of the selected entry, once chosen

    Thanks
    Yigal

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    A Content Control Dropdown cannot change item colours when they are selected. The most you can do is change the colour when the user exits the Content Control. This also means that, if they re-enter the Content Control to change the selection, the original colour will be applied to any new selection until they once again exit the Control.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    In my experience, the colour can change when you make a selection. You can also apply a local format to the empty 'placeholder' text but this only works once (if you then clear it again you are back to the default look). Doing this by code is not necessary but since you are creating the object in code, here is what you need to add after the code you already have.
    Code:
      With DRP_obj
        .DefaultTextStyle = "Intense Emphasis"      'this character style applied to chosen list item
        .Range.Style = "Emphasis"   'this character style applied to empty placeholder text until a selection is made 
      End With
    You could also use macros on exit or entry as Macropod suggests.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by Andrew Lockton View Post
    In my experience, the colour can change when you make a selection.
    But there isn't anything in a dropdown content control that allows one to change the colour upon selecting an item (e.g. red for item 1, yellow for item 2, green for item 3, etc.), which is what the OP is after. You can't even use a WindowSelectionChange event to trap the change.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I interpreted the request as asking simply for a different colour irrespective of the selection made.

    If the OP needs to trigger a macro to track changes in a Content Control prior to leaving that Content Control, he should have a look at Greg Maxey's page (http://gregmaxey.mvps.org/word_tip_p...om_events.html). Greg has provided a sample document that does exactly that. Appending the .DefaultTextStyle code line to Greg's sample code would achieve the desired result.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Tags for this Thread

Posting Permissions

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