×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Word97: How to fill a document template using a userform?

Word97: How to fill a document template using a userform?

Word97: How to fill a document template using a userform?

(OP)
Hi all,
I apologize for what is probably a ridiculously simple question.  I'm a relative newcomer to Word VBA (I've been programming in Access for a couple years now), and I need to update some templates.

Imagine something like your manual tax return.  That's kind of what these templates look like: they contain a lot of text, and a lot of table fields and "fill-in-the-blank" areas.  All of the text is written into the template itself, but the data needs to be filled in by code, after the user inputs it into a userform.

Currently, all of the areas that require data (about 40 of them) have unique mailmerge fields in them.  At the end of the data-entry, the user clicks a "continue" or "finish" button, which adds MailMerge sets to the document based on the data in the form.

This works, but it seems like there should be a much easier way to do it to me.  One that doesn't require hard-coding over 40 mail-merge names into the code.  So I'm looking for a better way.  It just seems like there should be a much more direct way of adding data to a document than this.  Or isn't there?

Thanks in advance for any help you can provide!

RE: Word97: How to fill a document template using a userform?

I have never used Mail merge so I don't really know what it does, but if I was going to populate field from a userform I would just put Labels on the Document then fill them from VB.

ThisDocument.Label1.Caption = TextBox1.Text

Let me know if this isn't what you are looking for.

RE: Word97: How to fill a document template using a userform?

Another way you can do it is to have Tables on your document and populate the cells of the tables.

This method would allow the user to change the fields after the Userform has closed.

This bit of code creates a table and populates two cells with data.

Private Sub AddTable()
Set myTable = ActiveDocument.Tables.Add(Selection.Range, 3, 3)
With myTable
    .Cell(1, 1).Range.InsertAfter "First Cell"
    .Cell(myTable.Rows.Count, myTable.Columns.Count).Range.InsertAfter "Last Cell"
End With
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close