Inserting Dropdowns or Check boxes in Userform

M

Mark

I have the following code in a userform embedded into a template, which
prompts for input of certain variables in a word document:

Private Sub CommandButton1_Click()

With ActiveDocument
.Bookmarks("Report_Number").Range _
.InsertBefore TextBox1
.Bookmarks("Date").Range _
.InsertBefore TextBox2
.Bookmarks("Location").Range _
.InsertBefore TextBox3
.Bookmarks("Spool_Details").Range _
.InsertBefore TextBox4
.Bookmarks("Pump_Pressure").Range _
.InsertBefore TextBox5
.Bookmarks("Name1").Range _
.InsertBefore TextBox6
.Bookmarks("Name2").Range _
.InsertBefore TextBox7
.Bookmarks("Name3").Range _
.InsertBefore TextBox8
End With

UserForm1.Hide
End Sub

What I would like to do is change the insertion of the following to either a
dropdown box with 2 or 3 different names or checkboxes with the same 2 or 3
names.

.Bookmarks("Name1").Range _
.InsertBefore TextBox6
.Bookmarks("Name2").Range _
.InsertBefore TextBox7
.Bookmarks("Name3").Range _
.InsertBefore TextBox8

How do I go about this?

Also, when I record a macro, how do I get the cursor to allow me to point
and select text? All it does now is change to an arrow with a cassette button
that does not allow me to do anything that I can tell.

Thanks in advance.
 
D

Doug Robbins - Word MVP

Simply replace the TextBox# with the name of the Combobox

You should give the controls meaningful names and you should also use the
..Text property even though it is the default property.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Mark

OK, call me stupid, but I cannot for the life of me get a combobox to work,
and I cannot find anything in the help files that actually helps. Can you
point me in the right direction to find how to add a combobox into the script
I am working on?

Cheers, Mark
 
D

Doug Robbins - Word MVP

Are you trying to get code to insert a combobox in a document or to insert
the item that is selected in a combobox on a userform into a bookmark in the
document?

For the latter, you first need to add the combobox to the userform and then
you need to populate it with the information to be selected. That is
usually done with the Initialize() event of the userform, and for just three
names, it would be simple enough to use the .AddItem function for a combobox

With Combobox1
.AddItem "Name1"
.AddItem "Name2"
.AddItem "Name3"
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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