help creating a table macro

C

Corey

Hello,

I am new to VBA but have been given the task of writing a macro to
create a table. There are a couple of things I'm having trouble with:

1- Can anyone tell me how to have the 'Insert Table' dialog box pop up
when the user runs the macro? I need to be able to have the number of
rows and columns be an option.

2- Along those same lines - if there is a particular style I need
applied to the bottom row - but the number of rows will vary - how do
I specify the bottom row as opposed to the number of the row?

3- I know there are issues with the 'column object'- is there a way to
define a particular column? Similarly, if I need to apply one style to
the left column - and another to all others - regardless of how many
there are - is there a way to do that?

Thanks so much!
Corey
 
E

Ed

1. To show the Table dialog, use
With Dialogs(wdDialogTableInsertTable)
.Show
End With

In VBA Help, look at "Displaying built-in Word dialog boxes" and "Built-in
dialog box argument lists" for more info on using this.

2. To access the bottom row of a table, set a variable (long or integer) to
Selection (or) ActiveDocument.Tables(1).Rows.Count (the "1" can be the Table
index number, if using a Document object, or (1) if using the Selection
object). You can then use Rows(count) to access the last row.

3. I would apply a style to the whole table, then specify what you want to
change. For a specific column, I've would up iterating through Cell(row, 1)
(for the first column).

Here's some code that inserts a table, then sets the last row and first
column to bold. I set an object to the inserted table because it made it
easier to work with.

Ed

Sub FooTbl()

Dim objTbl As Table
Dim cntRow As Long
Dim i As Long

Dialogs(wdDialogTableInsertTable).Show
Set objTbl = Selection.Tables(1)
cntRow = objTbl.Rows.Count

objTbl.Rows(cntRow).Range.Font.Bold = True

For i = 1 To cntRow
objTbl.Cell(i, 1).Range.Font.Bold = True
Next i

End Sub
 

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