View Single Post
 
Old 03-18-2014, 04:21 PM
Mooncat Mooncat is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Mar 2014
Posts: 3
Mooncat is on a distinguished road
Default Word 2007 VBA Combobox Conditional text problem

Hi all,
I'm having problems using a combobox to display text at a bookmark in Word 2007 and would be grateful for any clues

The code I have so far allows the user to select from the combobox and have the selected item text appear within a string at a bookmark when I run the code.
But I would like the user to be able to enter any word into the combobox and have that entry appear within the bookmark.

Example:
I have a combobox with the options Red, Green and Blue.
If pick one of these, the selected one appears at the bookmark,
however I don't know what to do if they should manually type another colour, say orange, into the combobox.

Any Ideas ?

Here is the code so far:
Code:
Sub testCombobox()
Dim objCC As ContentControl
Dim objLE As ContentControlListEntry
Dim isel As String
Set objCC = ActiveDocument.ContentControls(1)
For i = 1 To objCC.DropdownListEntries.Count
  If objCC.DropdownListEntries.Item(i).Text = objCC.Range.Text Then
    Set objLE = objCC.DropdownListEntries.Item(i)
    If objLE.Text = "Red" Then
      isel = " red"
    ElseIf objLE.Text = "Green" Then
      isel = " green"
    ElseIf objLE.Text = "Blue" Then
  isel = "blue"
    End If
  End If
Next i
ActiveDocument.Bookmarks("picked").Range.InsertAfter "You picked " & isel
End Sub
Thanks for reading
Regards,
Dan

Last edited by macropod; 03-18-2014 at 04:35 PM. Reason: Added code tags & formatting
Reply With Quote