Discussion Locked

Word 97 inserting text into a template

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a template and a subdocument. The template will be used by many peop[le in the purchasing department. Determined by what they are putting out for bids, the "special terms and conditions" subdocument will be brought in. I have creatd a check box on each item on the subdocuemt, to be checked if that is one of the items they will want to add to the template. Several items could be checked on the "Special terms and conditions" subdocument. I would like to bring all of the checked items intothe tmeplate at one time and then edit the template for the rest of the verbage they need to add. I cannot get the button I have created to pull up the subdocument and tehn I cannot figure out how to check each box for a checkmark and then copy themall to the template. Can anyone help me with this? I have experience in Access, but none in Word VBA. HELP!! Thanks so much! Connie

5 replies

by seagull data services

Have you considered using an Access Database to hold the terms an conditions and using mail merge to create the finished document?
I'm afraid I'm not too familiar with Word programming either.
John

by sankulpune

Hello cjones,

Create a table in the subdocument and leave the first row blank and one term/condition each in the second column of each row.

Remove check-boxes. I tried hard, but found it impossible to get their value.

Now open the subdocument("TermsTable.doc").
Type Y in the first column of the term/condition you want to include in the template. Leave other rows blank.

Now open the template document ("TemplateDoc.doc") and paste the following code in its VBE.

Sub CopyTerms()
' Code by SanganakSakha 6/7/01
' No comprehensive error checking
Dim subDoc As Document
Dim temDoc As Document
Dim termTable As Table
Set subDoc = Documents("TermsTable.doc")
Set temDoc = Documents("TemplateDoc.doc")
Set termTable = subDoc.Tables(1)
Dim totRos As Integer, totCols As Integer, cpTxt As String
totRos = termTable.Rows.Count
totCols = termTable.Columns.Count
Dim roKount As Integer, colKount As Integer
For roKount = 1 To totRos
If Left(Trim(CleanString(termTable.Cell(1, 1).Range.Text)), 1) = "Y" Then
cpTxt = Trim(CleanString(termTable.Cell(roKount, 2).Range.Text))
cpTxt = Left(cpTxt, Len(cpTxt) - 1)
temDoc.Activate
Selection.TypeText Text:=cpTxt
subDoc.Activate
End If
Next

Set subDoc = Nothing
Set temDoc = Nothing

End Sub

Run this code and selected terms/conditions will be pasted in the template.

I have successfully tried this code with a single line text in the second column.

I would be glad to provide any more help you may need in this regard.

With best regards,

Sanganaksakha,
Your Friend in Need.

by creed

Sanganaksakha, Thank you!
I have some questions about this, and I have developed some code that is useful however I have two problems with the code. Could you email me and I could send the code to you to look over and hopefully answer my questions.
My email address is cjones@valottery.state.va.us
I look forward to hearing from you, Thanks again, Connie

This discussion is closed to new replies.