How to Create 2 column table and continue adding rows 
Author Message
 How to Create 2 column table and continue adding rows

I am trying to create a word document for a friend who wants to be able to
open a specific document and, upon being opened, populate the document with
a 2 column table, and one row for every font in the system, and first column
have the font name in its own font, and the second column be plain readable
text as to the name of the font.

I am pretty good at programming in VB but not VBA, and have no idea about
document references.

Can anyone give me any pointers?

Heck, I got one working, but no table.  I tried to use my fav TAB(##)
function to tab over to another tabstop to create the "second column" but it
wasn't working, kept giving me an error about the index not correct?



Tue, 24 Feb 2004 13:39:31 GMT  
 How to Create 2 column table and continue adding rows
Hi Tim,

Quote:
> I am trying to create a word document for a friend who wants to
> be able to open a specific document and, upon being opened,
> populate the document with a 2 column table, and one row for
> every font in the system, and first column have the font name in
> its own font, and the second column be plain readable
> text as to the name of the font.

-------------------------------------------------------------

Dim oFont As Variant
Dim oTable As Table
Dim oRow As Row

Set oTable = ActiveDocument.Tables.Add( _
                Range:=Selection.Range, _
                NumRows:=1, _
                NumColumns:=2)

Set oRow = oTable.Rows.Last

For Each oFont In FontNames
    With oTable.Rows.Last
        .Cells(1).Range.Text = oFont
        .Cells(2).Range.Text = oFont
        .Cells(1).Range.Font.Name = oFont
    End With
    Set oRow = oTable.Rows.Add
Next oFont

-------------------------------------------------------------

Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.



Tue, 24 Feb 2004 14:28:39 GMT  
 How to Create 2 column table and continue adding rows
Hi Tim

Try this. It will add text to a document and then convert it into a table.
Sometimes as faster to do it this way around.
'------------------------------------
Dim sFont As Variant
Dim oRng As Range
Dim oTbl As Table

For Each sFont In Application.FontNames
    With Selection
        .Font.Name = sFont
        .TypeText sFont & vbTab & sFont & vbCr
    End With
Next

Set oTbl = ActiveDocument.Range.ConvertToTable _
        (Separator:=wdSeparateByTabs, NumColumns:=2)

oTbl.Sort FieldNumber:=2
oTbl.Columns(2).Select
Selection.Font.Name = "Times New Roman"
Selection.Collapse wdCollapseStart

--
Anna Bohman
Bra Utbildning AB, Sweden


Quote:
> I am trying to create a word document for a friend who wants to be able to
> open a specific document and, upon being opened, populate the document
with
> a 2 column table, and one row for every font in the system, and first
column
> have the font name in its own font, and the second column be plain
readable
> text as to the name of the font.

> I am pretty good at programming in VB but not VBA, and have no idea about
> document references.

> Can anyone give me any pointers?

> Heck, I got one working, but no table.  I tried to use my fav TAB(##)
> function to tab over to another tabstop to create the "second column" but
it
> wasn't working, kept giving me an error about the index not correct?



Tue, 24 Feb 2004 16:48:15 GMT  
 How to Create 2 column table and continue adding rows
Hey thanks both..... that's helped out perfect!


Wed, 25 Feb 2004 09:56:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. W97: Macro to create table (row x column) specified by user

2. Error creating rows with columns having different column width

3. Adding 'Continued' to Column breaks

4. Adding 'Continued' to Column Breaks

5. adding a table row, without setting same defaults as previous row

6. row heights of table rows added by vba

7. need help please:joined tables,add new entries based on one table columns

8. need help please:joined tables,add new entries based on one table columns

9. Normalizing non-normal tables already containing data;OR changing columns into rows

10. Trouble adding rows to DataTable : Error = System.IndexOutOfRangeException: Cannot find column 2

11. Getting row/column index of HTML TABLE cell

12. Adding and summing up database columns/rows

 

 
Powered by phpBB® Forum Software