Convert text to table macro from current selection

A

andreas

Dear Experts:

below macro converts the current selection (three lines with words
separated by tabs) into a table featuring 4 columns and three rows and
formats it with a user-defined table style.

Example (see code below):

text(tab) text(tab) text(tab) text
text(tab) text(tab) text(tab) text
text(tab) text(tab) text(tab) text


How can I expand the macro to perform the following tasks on any
selection:

Example:

.... retrieve the number of tabs in the first line of the current
selection (e.g. 6). 6 (six) tabs means 7 (seven) columns
.... retrieve the number of lines of the current selection (e.g. 8)

This variable number of columns (7) would be inserted into the
<NumColumns> part of the below code, the variable number of lines (3)
would be inserted into the <NumRows> part of the code.

So, summarizing the whole thing:
.... the code should identify the number of tabs in the first line of
the code
.... as well as the number of lines in the current selection and insert
the retrieved numbers in the macro code.

I hope I could make myself clear. Help is much appreciated. Thank you
very much in advance. Regards, Andreas



Sub Convert_Text_To_Table
Selection.ConvertToTable Separator:=wdSeparateByTabs,
NumColumns:=4, _
NumRows:=3, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Style = "User-Defined-Table-Style"
End With
End Sub
 
D

Doug Robbins - Word MVP

All you need is

Selection.ConvertToTable Separator:=wdSeparateByTabs

--
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
 
J

Jay Freedman

Hello Andreas,

The NumRows and NumColumns parameters of the ConvertToTable method are
optional (that is, you can omit them). Try removing them from your
code and running the resulting macro. I think you'll find that the
macro does the right thing in all cases, as it automatically analyzes
the number of tabs and paragraphs in the selection.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

andreas

All you need is

 Selection.ConvertToTable Separator:=wdSeparateByTabs

--
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














- Show quoted text -

ok, great. Thank you very much for your professinal help. Regards,
Andreas
 
A

andreas

Hello Andreas,

The NumRows and NumColumns parameters of the ConvertToTable method are
optional (that is, you can omit them). Try removing them from your
code and running the resulting macro. I think you'll find that the
macro does the right thing in all cases, as it automatically analyzes
the number of tabs and paragraphs in the selection.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.











- Show quoted text -

ok, great. Thank you very much for your terrific help.

Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top