L
LEU
I’m in way over my head on this one. We have student handout documents that
were set up in table formats. Our training department would like to get them
out of the table format. Part of the problem is that there was no consistent
way they were created. Some are one long table while others were divided into
multiple tables. Then with in a table it is different. Some have 3 columns
and others have 3 columns for part of the table and then it change to a
single column. The first column has the informational text in it. The second
is blank and is used as a spacer. The third column is used for notes to
support the first column. I’m trying to see if there is a way to convert
these tables to match my template. I have the following macro that I found on
this site and modified it. It gets the text out of the table format, if there
is only one table. I don’t now how to do it for more than one table or how to
get the text in column 3 and put it into a textbox.
I have set up a template so the left half of the page is for the
informational text and I have a macro that inserts a TextBox on the right
side of the page based on where their curser is at for the notes.
Dim SearchRange As Range
Dim TheTable As Table
Dim TheRow As Row
Set SearchRange = ActiveDocument.Range
If ActiveDocument.Tables.Count > 0 Then
Set TheTable = ActiveDocument.Tables(1)
For Each TheRow In TheTable.Rows
If Len(TheRow.Cells(1).Range.Paragraphs(1).Range.Text) > 2 Then
Set SearchRange = TheRow.Cells(1).Range.Paragraphs(1).Range
SearchRange.MoveEnd Unit:=wdCharacter, Count:=-1
SearchRange.Cut
Set SearchRange = TheRow.Cells(1).Range.Paragraphs(1).Range
With SearchRange
.Collapse wdCollapseEnd
.Move Unit:=wdCharacter, Count:=-1
.Paste
End With
If TheRow.Cells(1).Range.Paragraphs(1).Range.Text = vbCr Then
TheRow.Cells(1).Range.Paragraphs(1).Range.Delete
End If
End If
Next
TheTable.Rows.ConvertToText _
Separator:=wdSeparateByParagraphs, _
NestedTables:=False
End If
were set up in table formats. Our training department would like to get them
out of the table format. Part of the problem is that there was no consistent
way they were created. Some are one long table while others were divided into
multiple tables. Then with in a table it is different. Some have 3 columns
and others have 3 columns for part of the table and then it change to a
single column. The first column has the informational text in it. The second
is blank and is used as a spacer. The third column is used for notes to
support the first column. I’m trying to see if there is a way to convert
these tables to match my template. I have the following macro that I found on
this site and modified it. It gets the text out of the table format, if there
is only one table. I don’t now how to do it for more than one table or how to
get the text in column 3 and put it into a textbox.
I have set up a template so the left half of the page is for the
informational text and I have a macro that inserts a TextBox on the right
side of the page based on where their curser is at for the notes.
Dim SearchRange As Range
Dim TheTable As Table
Dim TheRow As Row
Set SearchRange = ActiveDocument.Range
If ActiveDocument.Tables.Count > 0 Then
Set TheTable = ActiveDocument.Tables(1)
For Each TheRow In TheTable.Rows
If Len(TheRow.Cells(1).Range.Paragraphs(1).Range.Text) > 2 Then
Set SearchRange = TheRow.Cells(1).Range.Paragraphs(1).Range
SearchRange.MoveEnd Unit:=wdCharacter, Count:=-1
SearchRange.Cut
Set SearchRange = TheRow.Cells(1).Range.Paragraphs(1).Range
With SearchRange
.Collapse wdCollapseEnd
.Move Unit:=wdCharacter, Count:=-1
.Paste
End With
If TheRow.Cells(1).Range.Paragraphs(1).Range.Text = vbCr Then
TheRow.Cells(1).Range.Paragraphs(1).Range.Delete
End If
End If
Next
TheTable.Rows.ConvertToText _
Separator:=wdSeparateByParagraphs, _
NestedTables:=False
End If