View Single Post
 
Old 04-30-2014, 03:37 PM
alshcover alshcover is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Apr 2014
Posts: 9
alshcover is on a distinguished road
Question How do I insert text that is dependent on the ComboBox value?

I created a UserForm. I added a ComboBox ("cboName") with 4 names available. When the User selects a name from cboName, the value will be inserted at a bookmark titled "Name" in the Word document.

However, there are ID numbers associated with each of the names that I would like inserted in the Word document at a location different than the "Name" bookmark. Therefore, is it possible to have the ID number automatically inserted in the Word document (at a bookmark titled "ID") based on User's selection in cboName?

For example, the ID numbers associated with each name:
  • Bob = 1
  • Cindy = 2
  • Peter = 3
  • Vanessa = 4
Here is the code:
Code:
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
    With ActiveDocument
        .Bookmarks("Name").Range.Text = cboName.Value
    End With
Application.ScreenUpdating = True
Unload Me
End Sub

Private Sub UserForm_Initialize()
    With cboName
        .AddItem "Bob"
        .AddItem "Cindy"
        .AddItem "Peter"
        .AddItem "Vanessa"
    End With
End Sub
Reply With Quote