A Combobox at a specific bookmark - can that be done in vba?

M

mypretty1

In my document I have defined some bookmark, at these bookmark I woul
like to have a combobox, where my users can select certain phrases.
bookmark can have the name Title, but my problem is that I cna't figur
out how to use this bookmark as a formfield with a combobox, wher
there has to be some phrases like "Accounting Manager" "Marketin
Director" etc. :(

Another problem that likely is to occure with the choise is that if th
title don't exits they have to be able to write their own title. Afte
what I can imagine I then have to change the combobox to a textfield
Correct me please if I am wrong ;)

I hope that someone can help me

Thanks a lot Mariann
 
D

Doug Robbins - Word MVP

I would suggest that you use a userform to gather not only the title, but
other items that you will probably want to place in specific places in the
document.

See the article “How to create a Userform” at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

In the Initialize event of the userform, you would populate the combobox
with the values that you want it to display. You can do that either by
using

cmbTitle.AddItem "Accounting Manger"
cmbTitle.AddItem "Marketing Director"

etc.

Or, you can store those entries in a separate Word document where it is easy
to maintain them and use the following code to populate the combobox:

Private Sub UserForm_Initialize()

Dim sourcedoc As Document, i As Long, myitem As range
' Modify the path in the following line so that it matches where you saved
the Titledata document
Set sourcedoc = Documents.Open(FileName:="j:\drive
D40\Documents\Titledata.doc")
For i = 2 To sourcedoc.Tables(1).rows.Count
Set myitem = sourcedoc.Tables(1).Cell(i, 1).range
myitem.End = myitem.End - 1
cmbTitle.AddItem myitem.Text
Next i
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

In all of this, I have assumed that you follow convention and name the
combobox cmbTitle.

To transfer the item selected in the combobox into the document, you would
use the following in a command button click event

ActiveDocument.Bookmarks("Title").Range.InsertBefore cmbTitle
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
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