Monday, August 10, 2009

MacroLabs | Converting Document Tables into Text

If you want to convert Microsoft Word Document to a Text file, this code might be able to help you. For example, your doc file contains tables and you want to convert it to formatted text file, follow the procedures below.

Private Sub ConvertTableToText()

Dim tTable As Table

For Each tTable In ActiveDocument.Tables
'this for each loop will check all tables in the document


tTable.ConvertToText Separator:="|", NestedTables:=True
'this will convert the table to text and each cell column will be divided by the "|" character
'you can also use other character to divide each cells

Next

End Sub


'Note: When you record your macro in Microsoft Word, it automatically selects a default separator for your ConvertToText function. Make sure you choose your own separator so that it would not encounter errors when used in other PC's

No comments:

Post a Comment