[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Create MSWord style for text table

Given some text, I want to convert it to a 2 column table (tab separator) with no borders.  Is there a way to create a "style" or some such thing so I can do this repeatedly without having to go through the entire process each time?
0
Cornelia Yoder
Asked:
Cornelia Yoder
  • 7
  • 6
1 Solution
 
Brian GeeCommented:
So I can understand this better, you have lines of text in a Word document that are separated by a single tab.

You would like to have a borderless table inserted in place of this text where the first portion of text before the tab is in the first (left) cell of the table and the second portion of text after the tab in the second (right) cell of the table.

Is this right? If so...

- Are the lines of text that are separated by a tab all on a single line?

- Would (you accept) a macro-based solution work for your objective?
0
 
Patrick MatthewsCommented:
Yodercm,

If you are interested in a macro-based solution, I have something that may interest you.

Patrick
0
 
Cornelia YoderArtistAuthor Commented:
Yes to your description, and the line of text may wrap but it's all one long line of text.  It looks like this

2N (tab) Description of the 2N ....yada yada

3H (tab) Description of the 3H .... yada yada

I want it to show as

2N            Description which may
                be more than one line
                like this is.

3H            Description etc.



So far the only way I have found to do this is with a table, and it's a pain to create a lot of tables and remove the borders.  Any mechanism where I can highlight the text, click a button or command and have it formatted like that would be wonderful.

I know nothing about macros in msword, but if it's tolerably easy to do, would be ok.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Patrick MatthewsCommented:
Sorry it took so long to get back to you.

As long as you are using tab as the column delimiter, and you want to convert the current selection to a table, add a new module to your VBA project and add this:

Sub MakeATable()

    Selection.ConvertToTable Separator:=wdSeparateByTabs

End Sub

Open in new window


To execute, just select the text you want to convert, and hit F8 to bring up the run macro dialog.
0
 
Cornelia YoderArtistAuthor Commented:
"...add a new module to your VBA project..."

I have not the slightest idea what this means nor how to do it.

By the way, this will be used in Word 2003, if that matters.
0
 
Patrick MatthewsCommented:
The version should not matter.  Try this:

1) Open Word

2) Hit Alt+F11 to get to the VB Editor

3) In your project explorer (it should be docked to the left of your screen), look for "Normal", which will be your normal template.  Right click it, and select Insert / Module from the popup menu

4) Paste the code I gave you in that new module, and hit Ctrl+S to save

Now, whenever you are in Word, select the range you want to convert to a table, hit Alt+F8, and select MakeATable from the dialog box.
0
 
Cornelia YoderArtistAuthor Commented:
Ok, that worked beautifully to make the table!  Is there a way I can preset the column widths (or other properties of the table)?   I would like the first column to be about 8 characters wide and the rest of the page width for the second column.
0
 
Patrick MatthewsCommented:
Yes, other properties can be set as well.

Please go ahead and list out your complete requirements.  I probably won't get to it until my tonight (US Eastern time).
0
 
Cornelia YoderArtistAuthor Commented:
That should be it.  Perhaps you would give me a reference to a tutorial or manual for this stuff so I could continue to do such things on my own?
0
 
Cornelia YoderArtistAuthor Commented:
By the way, can this be set on a single key, like a hotkey sort of thing?
0
 
Patrick MatthewsCommented:
Try experimenting with this:

Sub MakeATable()
    
    With Selection
        .ConvertToTable Separator:=wdSeparateByTabs, AutoFitBehavior:=wdAutoFitFixed
        .Tables(1).Columns(1).Width = Application.InchesToPoints(0.5)
    End With
    
End Sub

Open in new window


That makes the first column 0.5 inches wide; vary that up or down as desired.  There is not really a way to specify how many characters wide the column can be, as that is always going to depend upon your selected font, font size, and even your print driver.

I have yet to find a good book on programming for word, and while the VBA help file for Excel is usually very good, for Word it is not quite as helpful, IMHO.

You should probably start by turning on the macro recorder (under tools in the menu), doing stuff, and then checking to see what the recorder rendered.
0
 
Cornelia YoderArtistAuthor Commented:
If there is a way to do a single hotkey to run this macro, I'd appreciate knowing how to set that up, otherwise this is exactly what I needed.  

Thank you very much for your time to write this and explain it to me!
0
 
Patrick MatthewsCommented:
0
 
Cornelia YoderArtistAuthor Commented:
Got it!  Thanks so much :)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now