View Single Post
  #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