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 / February 2006

Tip: Looking for answers? Try searching our database.

Loop to insert rows in a word table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jesse  Yoburn - 17 Feb 2006 21:51 GMT
Hi all-

I have a table set up in MS Word with text fields populating every
cell.  I need to write a macro that, among other tasks, inserts a new
BLANK row after each row in the table.

That is, I have this:
--
aaa   bbb   ccc   ddd   eee
fff   ggg   hhh   iii   jjj
--

But need this:
--
aaa   bbb   ccc   ddd   eee

fff   ggg   hhh   iii   jjj

--

The table is quite large and will be growing regularly, so I'll need to
run the macro every few days and re-create this new formatting.  I've
done some work with macros in the past but loops have always been
trouble for me.

Thanks in advance for your help!
Helmut Weber - 17 Feb 2006 22:17 GMT
Hi Jesse,

it seems, one needs the selection for this:

Sub Test0987()
Dim r As Long    ' row
Dim t As Table
Set t = Selection.Tables(1)
For r = 1 To t.Rows.Count * 2 Step 2
  t.Cell(r, 1).Select
  Selection.InsertRowsBelow 1
Next
End Sub

To be used wisely!

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Doug Robbins - Word MVP - 18 Feb 2006 07:55 GMT
Always better/quicker to avoid using the Selection

Dim i As Long
With ActiveDocument.Tables(1)
   .Rows.Add
   For i = .Rows.Count - 1 To 2 Step -1
       .Rows.Add BeforeRow:=.Rows(i)
   Next i
End With

Signature

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

> Hi Jesse,
>
[quoted text clipped - 11 lines]
>
> To be used wisely!
 
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.