Insert Property in VB - Form Help

A

Angyl

I'm new to VB and following a tutorial for creating a Userform. I need a
simple modification to the code that has been given in this tutorial.

I created a Form in word using bookmarked form fields which have various
calculations on them.

The VB code I have for the Userform does this:

With ActiveDocument
.Bookmarks("ClientName").Range _
.InsertBefore ClientName
.Bookmarks("Description1").Range _
.InsertBefore Description1

End With

UserForm1.Hide

End Sub

The problem I'm having is with that "InsertBefore" command. I don't want it
to insert the text BEFORE the named bookmarked field, I want it *IN* the
named bookmarked field.

I tried searching for help in the VB for this and saw all sorts of
InsertAfter and at the end of the document or beginning of the document and
other types of Inserts but nothing seems to help me get something straight IN
the fields.

Help, please?
 
J

Jay Freedman

When you need to deal with ordinary bookmarks, see
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
for the technique for ensuring that the bookmark surrounds the
inserted text.

However, form fields in a protected form are *not* ordinary bookmarks.
They have a bookmark associated with them to serve as a name, but
you'll run into errors if you try to use the technique from the
article. Instead, use

With ActiveDocument
.FormFields("ClientName").Result = ClientName
.FormFields("Description1").Result = Description1
End With

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