Hi Doug,
So far my code looks like this:
Option Explicit
Private oVars As Variables
Private oSource As Document
Private oTable As Table
Private oRng As Range
Private strWidth As String
Private i As Long, j As Long, k As Long
Private m As Long, n As Long
Private Sub CommandButton1_Click()
Set oVars = ActiveDocument.Variables
oVars("Address").Value = Me.ListBox1.Column(0) & vbCr & _
Me.ListBox1.Column(1) & vbCr & _
Me.ListBox1.Column(2) & vbCr & _
Me.ListBox1.Column(3)
ActiveDocument.Fields.Update
Unload Me
End Sub
Private Sub CmdBtnCancel_Click()
Me.Hide
End Sub
Private Sub Label2_Click()
End Sub
Private Sub UserForm_Initialize()
Set oSource = Documents.Open(FileName:="C:\Addresses.doc", _
AddToRecentFiles:=False, _
Visible:=False)
Set oTable = oSource.Tables(1)
'Get the number of list members (i.e., table rows - 1 if header row is used)
i = oTable.Rows.Count - 1
'Get the number of list member attributes (i.e., table columns)
j = oTable.Columns.Count
'Set the number of columns in the Listbox
With Me.ListBox1
.ColumnCount = j
strWidth = .Width - 2
For k = 2 To j
strWidth = strWidth & ";" & 0
Next k
.ColumnWidths = strWidth
'Load list members into an array
ReDim myArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set oRng = oTable.Cell(m + 2, n + 1).Range
oRng.End = oRng.End - 1
myArray(m, n) = oRng.Text
Next m
Next n
'Populate the ListBox using the array
.List() = myArray
.ListIndex = 0
End With
'Close the source file
oSource.Close SaveChanges:=wdDoNotSaveChanges
End Sub
I just need to know what to do with my other listbox... replicate what I need to in order to get the desired effect as mentioned in my previous post.
I forgot to add one thing. The letters that I'm calling into my template also have reference fields, referencing the form fields on the first page of my template. Will these ref fields call the data from the first page when the userform enters them into
the document?
My entire goal for my template is this: I have several letters that I've been using for all of my clients where I need to send out the same letter of many types to request client information. The first page of this template is a sort of client intake form.
This form is a simple form template with fields you can just tab through and type in or select from dropdown boxes. When the user calls up the userform and selects the address and type of letter, I was hoping for the letter to reference some of the client
information I have included in pre-made ref fields referencing the fields on the first page so that when the correct letter is selected for the template, the information for that particular client will automatically enter into the document.
To me this sounds complicated and I hope it's possible, and I'm further hoping you understand what I'm trying to do and that you can help me again lol...
Thanks!