Reply
 
Thread Tools Display Modes
  #1   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

I use Word 2003.
I have a document which consist of a sequence of tables separated by
page breaks.
I can convert the document to text by putting the focus in each table in
turn and doing Table/Convert/Table to Text/Paragraph Marks/OK.
That is tedious in a 50 table document.
I would appreciate advice on some VBA to automate the process.

Each table consists of a full width row followed by two rows of 4
columns.

I hope this explains the layout
wwwwwww1
h1h2h3h4
t1t2t3t4

This is converted to
wwwwwww1
h1
h2
h3
h4
t1
t2
t3
t4

(It runs across rows first and then down columns)

I want it to convert to
wwwwwww1
h1
t1
h2
t2
h3
t3
h4
t4
(I want it to run down columns first and than across rows.)

While I could shuffle the output, it is tedious and error-prone.
I would value advice on simplifying the process.
--
Walter Briscoe
  #2   Report Post  
Posted to microsoft.public.word.tables
DeanH DeanH is offline
external usenet poster
 
Posts: 1,862
Default Need enhanced table to text conversion

If you are not worried about formatting, then you can select all of the
tables (Ctrl+A) or cursor before the first table and Ctrl+Shft+End, copy and
then you can use Paste Special, Unformatted Text, which will give you no
tables but text Tab Delimited.
Hope this helps
DeanH

"Walter Briscoe" wrote:

I use Word 2003.
I have a document which consist of a sequence of tables separated by
page breaks.
I can convert the document to text by putting the focus in each table in
turn and doing Table/Convert/Table to Text/Paragraph Marks/OK.
That is tedious in a 50 table document.
I would appreciate advice on some VBA to automate the process.

Each table consists of a full width row followed by two rows of 4
columns.

I hope this explains the layout
wwwwwww1
h1h2h3h4
t1t2t3t4

This is converted to
wwwwwww1
h1
h2
h3
h4
t1
t2
t3
t4

(It runs across rows first and then down columns)

I want it to convert to
wwwwwww1
h1
t1
h2
t2
h3
t3
h4
t4
(I want it to run down columns first and than across rows.)

While I could shuffle the output, it is tedious and error-prone.
I would value advice on simplifying the process.
--
Walter Briscoe

  #3   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 Fri,
5 Jun 2009 05:30:02 in microsoft.public.word.tables, DeanH
writes

That is certainly a fast way to eliminate the tables. It suffers the
same problem I had of re-ordering the text.

If you are not worried about formatting, then you can select all of the
tables (Ctrl+A) or cursor before the first table and Ctrl+Shft+End, copy and
then you can use Paste Special, Unformatted Text, which will give you no
tables but text Tab Delimited.
Hope this helps
DeanH

"Walter Briscoe" wrote:

I use Word 2003.
I have a document which consist of a sequence of tables separated by
page breaks.
I can convert the document to text by putting the focus in each table in
turn and doing Table/Convert/Table to Text/Paragraph Marks/OK.
That is tedious in a 50 table document.
I would appreciate advice on some VBA to automate the process.

Each table consists of a full width row followed by two rows of 4
columns.

I hope this explains the layout
wwwwwww1
h1h2h3h4
t1t2t3t4

This is converted to
wwwwwww1
h1
h2
h3
h4
t1
t2
t3
t4

(It runs across rows first and then down columns)

I want it to convert to
wwwwwww1
h1
t1
h2
t2
h3
t3
h4
t4
(I want it to run down columns first and than across rows.)

While I could shuffle the output, it is tedious and error-prone.
I would value advice on simplifying the process.
--
Walter Briscoe


--
Walter Briscoe
  #4   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Need enhanced table to text conversion

Use a macro containing the following code:

Dim i As Long, m As Long, n As Long
Dim crange As Range, target As Range
With ActiveDocument
For i = 1 To .Tables.Count
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



--
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, originally posted via msnews.microsoft.com
"Walter Briscoe" wrote in message
...
In message of Fri, 5
Jun 2009 05:30:02 in microsoft.public.word.tables, DeanH
writes

That is certainly a fast way to eliminate the tables. It suffers the same
problem I had of re-ordering the text.

If you are not worried about formatting, then you can select all of the
tables (Ctrl+A) or cursor before the first table and Ctrl+Shft+End, copy
and
then you can use Paste Special, Unformatted Text, which will give you no
tables but text Tab Delimited.
Hope this helps
DeanH

"Walter Briscoe" wrote:

I use Word 2003.
I have a document which consist of a sequence of tables separated by
page breaks.
I can convert the document to text by putting the focus in each table in
turn and doing Table/Convert/Table to Text/Paragraph Marks/OK.
That is tedious in a 50 table document.
I would appreciate advice on some VBA to automate the process.

Each table consists of a full width row followed by two rows of 4
columns.

I hope this explains the layout
wwwwwww1
h1h2h3h4
t1t2t3t4

This is converted to
wwwwwww1
h1
h2
h3
h4
t1
t2
t3
t4

(It runs across rows first and then down columns)

I want it to convert to
wwwwwww1
h1
t1
h2
t2
h3
t3
h4
t4
(I want it to run down columns first and than across rows.)

While I could shuffle the output, it is tedious and error-prone.
I would value advice on simplifying the process.
--
Walter Briscoe


--
Walter Briscoe


  #5   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 Sat, 6 Jun 2009
21:11:17 in microsoft.public.word.tables, Doug Robbins - Word MVP
writes

That is the sort of thing I had in mind. I start with 39 tables. It
converts the first and then fails , but leaves me with 28! It then
converts the second and fails. It then does nothing more. I am not sure
the logic is correct. The first through the loop works on Tables(1) and
the number of tables is reduced by 1. The next time, Tables(2) used to
be Tables(3), etc. I tried For i= Tables.Count to 1, but that also
failed 5941 The requested member of the collection does not exist in Set
crange = .Cell(1, 1).Range.
My suspicion is that the data is not quite what I think.

Before seeing your work, I tried:
For Each atable In ActiveDocument.Tables
If atable.Columns.Count = 4 Then
For i = 1 To 4
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Extend:=wdExtend
Selection.Cells.Merge
Next i
End If
Next atable

That did not seem to move onto the second table.

Use a macro containing the following code:

Dim i As Long, m As Long, n As Long
Dim crange As Range, target As Range
With ActiveDocument
For i = 1 To .Tables.Count
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


  #6   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Need enhanced table to text conversion

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


--
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, originally posted via msnews.microsoft.com
"Walter Briscoe" wrote in message
...
In message of Sat, 6 Jun 2009
21:11:17 in microsoft.public.word.tables, Doug Robbins - Word MVP
writes

That is the sort of thing I had in mind. I start with 39 tables. It
converts the first and then fails , but leaves me with 28! It then
converts the second and fails. It then does nothing more. I am not sure
the logic is correct. The first through the loop works on Tables(1) and
the number of tables is reduced by 1. The next time, Tables(2) used to
be Tables(3), etc. I tried For i= Tables.Count to 1, but that also
failed 5941 The requested member of the collection does not exist in Set
crange = .Cell(1, 1).Range.
My suspicion is that the data is not quite what I think.

Before seeing your work, I tried:
For Each atable In ActiveDocument.Tables
If atable.Columns.Count = 4 Then
For i = 1 To 4
Selection.MoveRight Unit:=wdCell
Selection.MoveDown Unit:=wdLine, Extend:=wdExtend
Selection.Cells.Merge
Next i
End If
Next atable

That did not seem to move onto the second table.

Use a macro containing the following code:

Dim i As Long, m As Long, n As Long
Dim crange As Range, target As Range
With ActiveDocument
For i = 1 To .Tables.Count
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


  #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
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting "Picture (Enhanced Metafile)" onto 1-cell table Bob Tables 2 December 10th 07 05:19 PM
Editing a Table Pasted from Excel into Word as a Picture (Enhanced Metafile) Brooks Microsoft Word Help 3 February 14th 07 03:41 PM
paste a table as enhanced metafile desperado Tables 0 January 22nd 06 10:45 AM
Macro for multiple Table --> Text conversion David Gareau via OfficeKB.com Tables 7 February 9th 05 04:23 AM
window enhanced metafile * Microsoft Word Help 1 February 1st 05 06:21 PM


All times are GMT +1. The time now is 05:47 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"