Two questions about Word UserForms

M

Mark

Question 1.

I am using the following UserForm 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

End With

I would like to use a Combo Box to add additional questions on the UserForm
with set answers contained in the Combo Box which would be placed at the
relevant bookmark location. How do I go about this?


Question 2.

In the same UserForm, I would like to add a yes/no question or a macro
button. If the answer is yes or the macro button is clicked, then the
document would create a second page identical to the first, with all the
bookmarked information included. If the answer was no or the macro button
left unclicked, then just the original page as laid out in the template would
be created with the contents of the bookmarked information included.

Is this possible, and if so how do I go about it?
 
S

Suzanne S. Barnhill

This is an end user NG; you're much more likely to get the help you need on
UserForms in microsoft.public.word.vba.userforms, to which I am
cross-posting this message.
 
M

Mark

Could you give me a link to the place where you have cross posted, because
for the life of me, I cannot find it!
 
J

Jonathan West

In the UserForm_Initialize event, you have to populate the combobox, like
this

ComboBox1.List = Array("Apples", "Pears", "Bananas", "Lemons", "Grapefruit")

It might be an idea to set the ListIndex property of the combobox to 0 to
ensure that something is guaranteed to be selected.

Then in the CommandButton1_Click, you do something like this to insert the
selected item into the document

With ActiveDocument
.Bookmarks("Fruit").Range _
.InsertBefore ComboBox1.Text
End With

Not sure I understand you. Do you want a second page with the information
duplicated as you have already entered on the UserForm, or do you want to be
able to run the UserForm again and insert a new lot of information?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

Doug Robbins - Word MVP

.Bookmarks("Report_Number").Range _
.InsertBefore ComboBox1.Value

I suggest that you give meaningful names to the controls on your userform.

--
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