Reply
 
Thread Tools Display Modes
  #1   Report Post  
David Gareau via OfficeKB.com
 
Posts: n/a
Default Macro for multiple Table --> Text conversion

I have some files that are filled with tables and cause me to have to print
2-3x as much, I want to convert the tables to text, but there's 100+
sometimes and I don't want to do each individually, I have read here that
the ONLY option is a macro, is this true? If so, any links to such a
macro, or ideas on how to make it? Thanks
david

--
Message posted via http://www.officekb.com
  #2   Report Post  
Pat Garard
 
Posts: n/a
Default

G'Day David,

The following Macro will go through a document and
convert all tables to text using tab separators.

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(intX).Select
Selection.Rows.ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

Cut and Paste as is.
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"David Gareau via OfficeKB.com" wrote in message
...
I have some files that are filled with tables and cause me to have to print
2-3x as much, I want to convert the tables to text, but there's 100+
sometimes and I don't want to do each individually, I have read here that
the ONLY option is a macro, is this true? If so, any links to such a
macro, or ideas on how to make it? Thanks
david

--
Message posted via http://www.officekb.com



  #3   Report Post  
Jay Freedman
 
Posts: n/a
Default

Hi Pat,

That's almost correct. As is, though, it will convert every second
table in the document and then stop with an error. The problem is that
after the first table is converted, the formerly second table becomes
..Tables(1). But by then intX has become 2, and the next conversion
affects what used to be the third table but is now .Tables(2). This
will continue until all the originally odd-numbered tables have been
converted, and then intX will reach a value greater than the number of
tables remaining in the document and an error will stop the macro.

The easiest fix is to change ActiveDocument.Tables(intX).Select to
ActiveDocument.Tables(1).Select, so each conversion affects the
current first table of the document. Since the loop condition
ActiveDocument.Tables.Count is evaluated only during the first pass,
it'll give you the correct number of passes.

Besides that, there's no need to select the table before converting
it. Your code will run faster (because there won't be any screen
redrawing) if you write the macro like this:

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Wed, 2 Feb 2005 09:11:06 +1100, "Pat Garard"
apgarardATbigpondDOTnetDOTau wrote:

G'Day David,

The following Macro will go through a document and
convert all tables to text using tab separators.

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(intX).Select
Selection.Rows.ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

Cut and Paste as is.
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"David Gareau via OfficeKB.com" wrote in message
m...
I have some files that are filled with tables and cause me to have to print
2-3x as much, I want to convert the tables to text, but there's 100+
sometimes and I don't want to do each individually, I have read here that
the ONLY option is a macro, is this true? If so, any links to such a
macro, or ideas on how to make it? Thanks
david

--
Message posted via http://www.officekb.com



  #4   Report Post  
Pat Garard
 
Posts: n/a
Default

Good One Jay!

Of course I never TESTED it did I? {:-{

How about....

Sub TablesToText()
While ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Wend
End Sub

......? [:-}
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"Jay Freedman" wrote in message
...
Hi Pat,

That's almost correct. As is, though, it will convert every second
table in the document and then stop with an error. The problem is that
after the first table is converted, the formerly second table becomes
.Tables(1). But by then intX has become 2, and the next conversion
affects what used to be the third table but is now .Tables(2). This
will continue until all the originally odd-numbered tables have been
converted, and then intX will reach a value greater than the number of
tables remaining in the document and an error will stop the macro.

The easiest fix is to change ActiveDocument.Tables(intX).Select to
ActiveDocument.Tables(1).Select, so each conversion affects the
current first table of the document. Since the loop condition
ActiveDocument.Tables.Count is evaluated only during the first pass,
it'll give you the correct number of passes.

Besides that, there's no need to select the table before converting
it. Your code will run faster (because there won't be any screen
redrawing) if you write the macro like this:

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Wed, 2 Feb 2005 09:11:06 +1100, "Pat Garard"
apgarardATbigpondDOTnetDOTau wrote:

G'Day David,

The following Macro will go through a document and
convert all tables to text using tab separators.

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(intX).Select
Selection.Rows.ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

Cut and Paste as is.
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"David Gareau via OfficeKB.com" wrote in message
om...
I have some files that are filled with tables and cause me to have to
print
2-3x as much, I want to convert the tables to text, but there's 100+
sometimes and I don't want to do each individually, I have read here
that
the ONLY option is a macro, is this true? If so, any links to such a
macro, or ideas on how to make it? Thanks
david

--
Message posted via http://www.officekb.com





  #5   Report Post  
Jay Freedman
 
Posts: n/a
Default

Hi Pat,

Yes, that would work. At least it would execute the same loop body the same
number of times.

When you have two constructions that both get the same results, then it's
reasonable to ask which one is "better", either noticeably faster or easier
to understand/maintain. In this case it could be a draw, but we'd have to
run both of them against the same file with a large number of tables to be
sure. I think the For..Next might run a bit faster than the While..Wend,
because the loop-ending condition of the For loop is evaluated only once.
But it very much depends on how the VBA developers implemented the two kinds
of loops in machine language.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Pat Garard wrote:
Good One Jay!

Of course I never TESTED it did I? {:-{

How about....

Sub TablesToText()
While ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Wend
End Sub

.....? [:-}

"Jay Freedman" wrote in message
...
Hi Pat,

That's almost correct. As is, though, it will convert every second
table in the document and then stop with an error. The problem is
that after the first table is converted, the formerly second table
becomes .Tables(1). But by then intX has become 2, and the next
conversion affects what used to be the third table but is now
.Tables(2). This will continue until all the originally odd-numbered
tables have been converted, and then intX will reach a value greater
than the number of tables remaining in the document and an error
will stop the macro.

The easiest fix is to change ActiveDocument.Tables(intX).Select to
ActiveDocument.Tables(1).Select, so each conversion affects the
current first table of the document. Since the loop condition
ActiveDocument.Tables.Count is evaluated only during the first pass,
it'll give you the correct number of passes.

Besides that, there's no need to select the table before converting
it. Your code will run faster (because there won't be any screen
redrawing) if you write the macro like this:

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Wed, 2 Feb 2005 09:11:06 +1100, "Pat Garard"
apgarardATbigpondDOTnetDOTau wrote:

G'Day David,

The following Macro will go through a document and
convert all tables to text using tab separators.

Sub TablesToText()
Dim intX As Integer
For intX = 1 To ActiveDocument.Tables.Count
ActiveDocument.Tables(intX).Select
Selection.Rows.ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Next
End Sub

Cut and Paste as is.
--
Regards,
Pat Garard
Melbourne, Australia
_______________________

"David Gareau via OfficeKB.com" wrote in
message ...
I have some files that are filled with tables and cause me to have
to print
2-3x as much, I want to convert the tables to text, but there's
100+ sometimes and I don't want to do each individually, I have
read here that
the ONLY option is a macro, is this true? If so, any links to
such a macro, or ideas on how to make it? Thanks
david

--
Message posted via http://www.officekb.com





  #6   Report Post  
David Gareau via OfficeKB.com
 
Posts: n/a
Default

Hey thanks for the quick replies:
I have never used macros.

How would I use this one, how do I input it and where, or if that's lengthy
and has been addressed elsewhere could you direct me to such a resource.

Thanks
David

--
Message posted via http://www.officekb.com
  #7   Report Post  
Suzanne S. Barnhill
 
Posts: n/a
Default

See http://www.gmayor.com/installing_macro.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"David Gareau via OfficeKB.com" wrote in message
...
Hey thanks for the quick replies:
I have never used macros.

How would I use this one, how do I input it and where, or if that's

lengthy
and has been addressed elsewhere could you direct me to such a resource.

Thanks
David

--
Message posted via http://www.officekb.com


  #8   Report Post  
Doug
 
Posts: n/a
Default

I am having a similar problem!
The macro TablesToText() almost does the trick but....

The result using a 3x2 table is similar to this:
(Cell1,Cell2,Cell3, etc are just prior to the end-of-cell marker in each
cell)

This is line one

Line two

Line three

Cell1 This is line one

Line two

Line three

Cell2 This is line one

Line two

Line three

Cell3

This is line one

Line two

Line three

Cell4 This is line one

Line two

Line three

Cell5 This is line one

Line two

Line three

Cell6



Note: Cell 1 and Cell2 are separated by a Tab but Cell 3 is NOT. Cell 3
runs together with Cell4.



What modification is needed to the macro to get a Tab to separate the last
cell in a row from the first cell in the next row?


Sub TablesToText()
While ActiveDocument.Tables.Count
ActiveDocument.Tables(1).ConvertToText _
Separator:=wdSeparateByTabs, _
NestedTables:=True
Wend
End Sub

Thanks
Doug


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
How do I tie Table Numbers to references in the text? Tim Tables 4 May 6th 23 08:49 PM
Resources for Long Document Management Jason Langkamer-Smith Microsoft Word Help 9 January 17th 05 08:17 PM
Any way to link text with Figure or Table number? Richard Stanford Microsoft Word Help 1 January 4th 05 02:32 PM
Outline Renee Hendershott Page Layout 2 December 25th 04 02:49 PM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 07:44 AM.

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"