Sub DataSorcerer()
Dim tbl As Table 'Table object
Dim x As Integer, y As Integer 'Counters
Dim intRows As Integer 'Total rows in table
Dim intCols As Integer 'Total Columns in table
Dim intGotVal As Integer 'Test for blank cells
'Select Entire Document and replace all line breaks
'with temporary place holder
Selection.WholeStory
With Selection.Find
.Text = "^p"
.Replacement.Text = "<REPLACEMENT>"
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
With Selection.Find
.Text = "^l"
.Replacement.Text = "<REPLACEMENT>"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Convert all tables to text w/ paragraph symbols
'used as delimiters
For Each tbl In ActiveDocument.Tables
tbl.Select
tbl.Rows.ConvertToText Separator:=wdSeparateByParagraphs
Next tbl
'Remove all section breaks from document
Selection.WholeStory
With Selection.Find
.Text = "^b"
.Replacement.Text = "^p"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Replace all double line breaks w/ single line breaks
Selection.WholeStory
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Replace temporary place holder w/ tabs to be used
'when text is converted to table
Selection.WholeStory
With Selection.Find
.Text = "<REPLACEMENT>"
.Replacement.Text = "^t"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Select entire document then convert to table w/ tabs
'as delimiter
Selection.WholeStory
Selection.ConvertToTable Separator:=wdSeparateByTabs
'Count rows and columns and set current table object
intRows = ActiveDocument.Tables(1).Rows.Count
intCols = ActiveDocument.Tables(1).Columns.Count
Set tbl = ActiveDocument.Tables(1)
'Check for and remove blank rows
For x = 1 To intRows
intGotVal = 0
For y = 1 To intCols
If tbl.Cell(x, y).Range.Characters.Count > 1 Then
intGotVal = intGotVal + 1
y = intCols
Else
'Do Nothing
End If
Next y
If intGotVal = 0 Then
tbl.Rows(x).Delete
x = x - 1
Else
'Do Nothing
End If
Next x
'Check for and remove blank columns
For y = 1 To intCols
If y > tbl.Columns.Count Then
y = intCols
Else
intGotVal = 0
For x = 1 To intRows
If tbl.Cell(x, y).Range.Characters.Count > 1 Then
intGotVal = intGotVal + 1
x = intRows
Else
'Do Nothing
End If
Next x
If intGotVal = 0 Then
tbl.Columns(y).Delete
y = y - 1
Else
'Do Nothing
End If
End If
Next y
'Reset column count and insert blank row
'adding a column heading to each cell
intCols = tbl.Columns.Count
tbl.Rows(1).Select
Selection.InsertRows 1
For y = 1 To intCols
tbl.Cell(1, y).Select
Selection.Text = "Line" & y
Next y
End Sub