Here is my code:
Option Explicit
Private oBMs As Bookmarks
Private Sub UserForm_Initialize()
Dim myType
Set oFF = ActiveDocument.FormFields
myType = Split("CONTINUOUS|INFORMATION|REFERENCE", "|")
With Cmb1
.List = myType
.ListIndex = 0
.MatchRequired = True
End With
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range, m As
Long, n As Long
' Modify the path in the following line so that it matches where you
Saved Clients.Doc
Application.ScreenUpdating = False
' Open the file containing the client details
Set sourcedoc = Documents.Open(FileName:="u:\Procedure Master
Template\Clients.doc")
' Get the number or clients = number of rows in the table of client
details less one
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table of client details
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
ListBox1.ColumnCount = j
' Define an array to be loaded with the client data
Dim myArray() As Variant
'Load client data into MyArray
ReDim myArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
myArray(m, n) = myitem.Text
Next m
Next n
' Load data into ListBox1
ListBox1.List() = myArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
On Error Resume Next
Set oFF = ActiveDocument.FormFields
Set oBMs = ActiveDocument.Bookmarks
Text1.Value = oBMs("bknbr").Range.Text
Text2.Value = oBMs("bkRevision").Range.Text
Text3.Value = oBMs("bktitle").Range.Text
Cmb1.Value = oBMs("bkUse").Range.Text
Text4.Value = oBMs("bkDIC").Range.Text
Text5.Value = oBMs("bkPCN").Range.Text
Text6.Value = oBMs("bkQPR").Range.Text
Text7.Value = oBMs("bkExt1").Range.Text
Text8.Value = oBMs("bkSponsor").Range.Text
Text9.Value = oBMs("bkExt2").Range.Text
Text10.Value = oBMs("bkDate").Range.Text
End Sub
and
Private Sub cmdOK_Click()
FillBookmark "bknbr", Text1.Text
FillBookmark "bknbr2", Text1.Text
FillBookmark "bknbr3", Text1.Text
FillBookmark "bknbr4", Text1.Text
FillBookmark "bkRev", Text2.Text
FillBookmark "bkRevision", Text2.Text
FillBookmark "bktitle", Text3.Text
FillBookmark "bktitle1", Text3.Text
FillBookmark "bkuse", Cmb1.Value
FillBookmark "bkuse1", Cmb1.Value
FillBookmark "bkDic", Text4.Text
FillBookmark "bkPCN", Text5.Text
FillBookmark "bkQPR", Text6.Text
FillBookmark "bkExt1", Text7.Text
FillBookmark "bkSponsor", Text8.Text
FillBookmark "bkExt2", Text9.Text
FillBookmark "bkDate", Text10.Text
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
FillBookmark "bkProTitle", Addressee
Me.Hide
End Sub
LEU