View Single Post
  #7   Report Post  
Posted to microsoft.public.word.tables
Walter Briscoe Walter Briscoe is offline
external usenet poster
 
Posts: 42
Default Need enhanced table to text conversion

In message of Sun, 7 Jun 2009
08:56:49 in microsoft.public.word.tables, Doug Robbins - Word MVP
writes

Thanks, again, for your efforts.
When I ran the code, it hit something like "no such object" at "Set
crange = .Cell(1, 1).Range". I realised the data did not quite fit the
model. I threw together this code to show each table in turn:

With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).Select
MsgBox "Selected table " & i ' Could not find 2 sec wait code!
Next i
End With

That showed I had a couple of tables which had more than one set of data
in them. I split those tables and things went better.
I tidied up page breaks - the original document was inconsistent in use
of page and section breaks. I found I could find section breaks, but not
replace them. I did not bother to construct a loop of find section
break, delete, insert page break but did that by hand. At the end, I
wished I had written a macro to do so.

One thing that is lost in the data is font information. e.g. Some Arial,
48 point, centered data becomes Arial 12 point, left-justified

Thanks, yet again, for your valuable help.

I should have realised that would happen as when the table is deleted,
the number of tables in the document changes (I developed the code
working on a document that contained just one table. The following
code starts with the last table in the document and works towards the
first and will overcome that problem:

Dim i As Long, m As Long, n As Long
Dim crange As Range, target As Range
With ActiveDocument
For i = .Tables.Count To 1 Step - 1
With .Tables(i)
Set target = .Range.Duplicate
target.Collapse wdCollapseEnd
Set crange = .Cell(1, 1).Range
crange.End = crange.End - 1
target.Text = crange.Text
For m = 1 To .Columns.Count
For n = 2 To .Rows.Count
Set crange = .Cell(n, m).Range
crange.End = crange.End - 1
target.Text = target.Text & vbCr & crange.Text
Next n
Next m
.Delete
End With
Next i
End With



--
Walter Briscoe