|
|
|
|
|
|
Word
|
Convert Table To Text And Convert Text To Table
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2002
|
Submitted by:
|
MOS MASTER
|
Description:
|
The sub ConvertTableToText turns the bookmarked table to tab delimited text. The sub ConvertTextToTable turns the bookmarked range (Tab delimited) to a table both subs have a check to look for the correct table count in the bookmarked range.
|
Discussion:
|
Converting a delimited range to a table can be very handy at times. And sometimes you need the opposite to happen. (Convert table to text) Both subs use a bookmark to locate the right area to work on.
|
Code:
|
instructions for use
|
Option Explicit
Sub ConvertTableToText()
Dim oTable As Word.Table
If ActiveDocument.Bookmarks("bmTable").Range.Tables.Count _
<> 1 Then Exit Sub
Set oTable = ActiveDocument.Bookmarks("bmTable").Range.Tables(1)
oTable.ConvertToText Separator:=wdSeparateByTabs
Set oTable = Nothing
End Sub
Sub ConvertTextToTable()
Dim oRange As Word.Range
If ActiveDocument.Bookmarks("bmTable").Range.Tables.Count _
<> 0 Then Exit Sub
Set oRange = ActiveDocument.Bookmarks("bmTable").Range
oRange.ConvertToTable Separator:=wdSeparateByTabs
Set oRange = Nothing
End Sub
|
How to use:
|
- Open your Word document.
- Press Alt + F11 to open VBE.
- Insert-Module. (Insert -> module)
- Paste the code there in the window at right. (F7)
- Close VBE (Alt + Q or press the X in the top right hand corner).
- Save the file.
|
Test the code:
|
- From Word, press Alt + F8 to open the macro dialog box.
- Select ConvertTableToText to convert a table to text
- Click Run.
- From Word, press Alt + F8 to open the macro dialog box.
- Select ConvertTextToTable to convert text to a table
- Click Run.
|
Sample File:
|
Convert table to text.zip 11.24KB
|
Approved by mdmackillop
|
This entry has been viewed 139 times.
|
|