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 / November 2007

Tip: Looking for answers? Try searching our database.

Same activity within all tables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stevewy@hotmail.com - 16 Nov 2007 12:42 GMT
I have some addresses and contact details which have been churned out
by a database program, and I need to put them into a mail-mergable
format.  It was originally extracted as RTF, but now it is in Word, I
find that each record is in its own little table, along with some
unwanted details.

I am trying to write a short macro that would go through each table in
the document in turn, and if it detects there are more than seven rows
in the table (not all the records are the same length), it will delete
row 7 of the table, then move on to the next table.

I have a basic structure for doing things to each table in a document:

Sub Table_Stuff()
Dim t As Table
For Each t In ActiveDocument.Tables
With t
    [stuff to do in the table]
End With
Next
End Sub

... but I cannot get the macro to delete row 7.  Now, since not all
tables have seven rows, I first need to ascertain this by using, I
presume, Selection.Information(wdMaximumNumberOfRows).  However, I
can't think of how to adapt this command for use in this macro.

I tried:

t.Information(wdMaximumNumberOfRows)

but that doesn't work.

Can anyone give me any suggestions?

Thanks so much.

Steve Wylie
Kent, England
macropod - 16 Nov 2007 13:46 GMT
Hi Steve,

Assuming you want to delete all rows beyond the 6th, try:

Sub TrimTables()
Dim oTbl As Table
Dim i As Integer
For Each oTbl In ActiveDocument.Tables
   If oTbl.Rows.Count > 6 Then
       For i = oTbl.Rows.Count To 7 Step -1
           oTbl.Rows(i).Delete
       Next
   End If
Next
End Sub

Otherwise, if it's just the 7th row:

Sub TrimTables()
Dim oTbl As Table
Dim i As Integer
For Each oTbl In ActiveDocument.Tables
   If oTbl.Rows.Count > 6 Then
      oTbl.Rows(7).Delete
   End If
Next
End Sub

Cheers
Signature

macropod
[MVP - Microsoft Word]
-------------------------

>I have some addresses and contact details which have been churned out
> by a database program, and I need to put them into a mail-mergable
[quoted text clipped - 35 lines]
> Steve Wylie
> Kent, England
stevewy@hotmail.com - 16 Nov 2007 15:36 GMT
Ah!  Thanks for that - obviously I'd been barking up the wrong tree
with Selection.Information(wdMaximumNumberOfRows).  I will keep hold
of your response as well, and hopefully it will come in useful if I
have any similar operations to do in the future.

Thanks again.

Steve
 
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.