I sent you an email with two documents attached. The first was the list as I
get it, and the second was the labels I am creating. Please let me know if
you had any difficulty in receiving them.
A macro containing the following code will create a document that you sent
to me that contains a table that could be used as a data source for a label
type mail merge. With a bit more work, it could be made to create the
labels directly. Note that there was one irregularity with the numbering in
the file that you sent me that I had to manually adjust to get this to work
correctly - that irregularity was a period after the first level 4
Dim Source As Document, Target As Document
Dim STable As Table, TTable As Table
Dim srange As Range, num As Range
Dim Project As String
Dim Line2 As String, Line3 As String, Line4 As String, Line5 As String,
Line6 As String
Dim Flag As String
Dim i As Long, j As Long, k As Long
Dim TRow As Row
Set Source = ActiveDocument
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13{1,}"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Set srange = Source.Range
srange.start = srange.start + InStr(srange, "Project")
Set srange = srange.Paragraphs(1).Range
srange.start = srange.start + InStr(srange, "[")
srange.End = srange.End - 2
Project = srange.Text
Source.ConvertNumbersToText
Set srange = Source.Range
srange.start = srange.Paragraphs(2).Range.start
srange.start = srange.start + InStr(srange, "MASTER FILE LIST")
srange.start = srange.Paragraphs(2).Range.start
For i = 1 To srange.Paragraphs.Count
Set num = srange.Paragraphs(i).Range
num.End = num.start + InStr(num, vbTab)
j = 0
For k = 1 To Len(num)
If num.Characters(k) = "." Then
j = j + 1
End If
Next k
For k = 1 To j
num.InsertBefore vbTab
Next k
Next i
srange.ConvertToTable vbTab
Set STable = srange.Tables(1)
Set Target = Documents.Add
Set TTable = Target.Tables.Add(Target.Range, 1, 1)
With STable
For i = 1 To .Rows.Count
With .Rows(i)
If Len(.Cells(1).Range) > 2 Then
Set srange = .Cells(1).Range
srange.End = srange.End - 1
Line2 = srange.Text & vbTab
Set srange = .Cells(2).Range
srange.End = srange.End - 1
Line2 = Line2 & srange.Text
TTable.Cell(i, 1).Range.Text = Project & vbCr & Line2
TTable.Rows.Add
ElseIf Len(.Cells(2).Range) > 2 Then
Set srange = .Cells(2).Range
srange.End = srange.End - 1
Line3 = srange.Text & vbTab
Set srange = .Cells(3).Range
srange.End = srange.End - 1
Line3 = Line3 & srange.Text
TTable.Cell(i, 1).Range.Text = Project & vbCr & Line2 & vbCr
& Line3
TTable.Rows.Add
ElseIf Len(.Cells(3).Range) > 2 Then
Set srange = .Cells(3).Range
srange.End = srange.End - 1
Line4 = srange.Text & vbTab
Set srange = .Cells(4).Range
srange.End = srange.End - 1
Line4 = Line4 & srange.Text
TTable.Cell(i, 1).Range.Text = Project & vbCr & Line3 & vbCr
& Line4
TTable.Rows.Add
ElseIf Len(.Cells(4).Range) > 2 Then
Set srange = .Cells(4).Range
srange.End = srange.End - 1
Line5 = srange.Text & vbTab
Set srange = .Cells(5).Range
srange.End = srange.End - 1
Line5 = Line5 & srange.Text
TTable.Cell(i, 1).Range.Text = Project & vbCr & Line4 & vbCr
& Line5
TTable.Rows.Add
ElseIf STable.Columns.Count > 5 Then
Set srange = .Cells(5).Range
srange.End = srange.End - 1
Line6 = srange.Text & vbTab
Set srange = .Cells(6).Range
srange.End = srange.End - 1
Line6 = Line6 & srange.Text
TTable.Cell(i, 1).Range.Text = Project & vbCr & Line5 & vbCr
& Line6
TTable.Rows.Add
End If
End With
Next i
End With
With TTable
For i = 1 To .Rows.Count
With .Cell(i, 1).Range
.Paragraphs(.Paragraphs.Count).Range.Font.Bold = True
End With
Next i
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I sent you an email with two documents attached. The first was the list as
>I
[quoted text clipped - 92 lines]
>> >>> >of
>> >>> > the headings. How can I do that with a mail merge?
hueffmea - 02 May 2008 15:42 GMT
I ran the script and I get an Invalid Outside Procedure error code at
Set Source = ActiveDocument
It looks to me as if it's not orphaned, but then to say I'm new to VB is an
understatement.
Can you tell me what I might be doing wrong?
> A macro containing the following code will create a document that you sent
> to me that contains a table that could be used as a data source for a label
[quoted text clipped - 211 lines]
> >> >>> >of
> >> >>> > the headings. How can I do that with a mail merge?
hueffmea - 02 May 2008 18:20 GMT
Oddly enough, even though putting Sub at the top didn't seem to work, putting
public Sub did. I now have the list, and am working on figuring out how to
get it into the avery 5262 label template. Incidentally how much is your
consulting fee for something like this?
> I ran the script and I get an Invalid Outside Procedure error code at
> Set Source = ActiveDocument
[quoted text clipped - 219 lines]
> > >> >>> >of
> > >> >>> > the headings. How can I do that with a mail merge?