Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

help creating a table macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Corey - 01 Dec 2004 19:40 GMT
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
Ed - 01 Dec 2004 21:02 GMT
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

> Hello,
>
[quoted text clipped - 16 lines]
> Thanks so much!
> Corey
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.