View Single Post
 
Old 01-20-2015, 07:15 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Graham has shown you one way. I'm going to Shanghai part of his code to show you another. If you define all of your variables in the combobox (multi-column) you can do it like this:

Code:
Private Sub UserForm_Initialize()
  With Me.ComboBox1
    .AddItem
    .List(.ListCount - 1, 0) = "Cleveland"
    .List(.ListCount - 1, 1) = "A city in northwestern Ohio, USA"
    .AddItem
    .List(.ListCount - 1, 0) = "Cincinnati"
    .List(.ListCount - 1, 1) = "A city in southwestern Ohio, USA"
  End With
End Sub
Private Sub CommandButton1_Click()
  On Error GoTo Err_UserDefined
   FillBM "bmCityName", Me.ComboBox1.Column(0)
   FillBM "bmDescription", Me.ComboBox1.Column(1)
lbl_Exit:
   Unload Me
   Exit Sub
Err_UserDefined:
  FillBM "bmCityName", Me.ComboBox1.Value
  FillBM "bmDescription", "Not defined"
  Resume lbl_Exit
End Sub
Public Sub FillBM(strBMName As String, strValue As String)
Dim oRng As Range
  With ActiveDocument
    On Error GoTo lbl_Exit
    Set oRng = .Bookmarks(strBMName).Range
    oRng.Text = strValue
    oRng.Bookmarks.Add strBMName
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote