Combo box selection to appear at bookmark

S

Sammy

I've searched for help within this group on this topic, but I'm not finding
my answer. I have a survey template which uses a Userform to collect
information from the user and then spits the data in the doc via bookmark
placement. I want to use a combo box so the user can select a name from a
list and then that name is entered at the bookmark. I have the following
within the macro to populate the combo box, but I don't know how to then have
the text appear at the bookmark. The bookmark is "bkSignature". Can you
help? I'm using Word 03. Thank you.

Combobox1.additem "Joe Smith"
Combobox1.additem "Sue Jones"
 
J

Jay Freedman

Hi Sammy,

In the click procedure of the OK button on the userform, use code like
this:

Private Sub CommandButton1_Click()
Dim myRange As Range
With ActiveDocument
If .Bookmarks.Exists("bkSignature") Then
Set myRange = .Bookmarks("bkSignature").Range
Else
Set myRange = Selection.Range
End If

myRange.Text = ComboBox1.Value

.Bookmarks.Add Name:="bkSignature", Range:=myRange
End With
Me.Hide
End Sub

For more information about this technique and why it's necessary, see
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top