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