Code:
Current Resident Current Resident Current Resident
629 MAIN STREET 618 MAIN STREET 123 MAIN STREET
MONTELLO WI 53949 MONTELLO WI 53949 MONTELLO WI 53949
I have a list in Word (above) that my client wants me to put into Excel. The problem is that it isn't setup on a label template, but the author did it using tab stops and spaces. I'm trying to take the list (22 pages) and send it to XL so that it's a genuine list (first col= Name, 2nd col = Address 3rd col = CSZ)
Some of these have four lines, some have 3. Also, some use the Tab character in it, which I've tried to split out, but some just use spaces. This is what I've tried.
Code:
Sub TestSelect2()
Dim XL As New Excel.Application
Dim i As Integer
Dim arr As Variant
Dim j As Variant
Dim k As Integer
Dim L As Integer
Set XL = New Excel.Application
With XL
.Visible = True
.Workbooks.Add
End With
On Error Resume Next
XL.Range("A1").Activate
XL.ActiveCell.Value = "Name"
XL.ActiveCell.Offset(0, 1).Value = "Address"
XL.ActiveCell.Offset(0, 2).Value = "NACSZ"
XL.ActiveCell.Offset(0, 3).Value = "Unknown"
For i = 1 To Word.ActiveDocument.Paragraphs.Count
j = Word.ActiveDocument.Paragraphs(i)
arr = Split(j, vbTab)
XL.ActiveCell.Offset(1, 0).Activate
For k = LBound(arr) To UBound(arr)
L = L + 1
If L = 1 Then
XL.ActiveCell.Value = arr(k)
ElseIf L = 2 Then
XL.ActiveCell.Offset(0, 1).Value = arr(k)
ElseIf L = 3 Then
XL.ActiveCell.Offset(0, 2).Value = arr(k)
ElseIf L = 4 Then
XL.ActiveCell.Offset(0, 3).Value = arr(k)
L = 0
Exit For
End If
'Debug.Print arr(k)
Next k
XL.ActiveCell.Offset(1, 0).Activate
Next i
End Sub
Any help will be greatly appreciated.
Ron Repp
If gray hair is a sign of wisdom, then I'm a genius.
My newest novel: Wooden Warriors