Converting tables

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
 
D

Doug Robbins - Word MVP

As far as I can see, and from tests on a table in a document, the following
part of your code does absolutely nothing

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

The only part that is doing anything is the

TheTable.Rows.ConvertToText _
Separator:=wdSeparateByParagraphs, _
NestedTables:=False

If you want to convert all of the tables in the document to text, use

Dim atable as Table
For each atable in ActiveDocument.Tables
atab.ConvertToText _
Separator:=wdSeparateByParagraphs, _
NestedTables:=False
Next atable


--
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
 
L

LEU

Thanks Doug,

That took care of the table issue. How would I flag the text in the third
column before I run this so afterwards I can copy the text into Textboxes. I
was thinking of changing the text to red.

LEU
 
D

Doug Robbins - Word MVP

I do not really know what you are starting with or, what you want to create.
However, whatever it is, I would probably not go about it that way.

If I have the complete picture, I would then be able to determine the way in
which I would do it, but without it, any suggestion that I make would just
be like a shot in the dark.

--
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
 
L

LEU

Doug,

When I get into work in the morning I could send you a copy of what I have
and a copy of what I want to end up with. If that will help.


LEU
 
D

Doug Robbins - Word MVP

Yes, that would help. Remove the upper case letters from my email address.

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top