atw: Re: Word macro - set table width
- From: "Elizabeth Fullerton" <Elizabeth_Fullerton@xxxxxxxxxxx>
- To: <austechwriter@xxxxxxxxxxxxx>
- Date: Thu, 23 Dec 2004 10:27:33 +1100
Here is a macro I acquired from somewhere (MVPS, i think) (or this
list!), which removes all the empty table rows in a document. I think
you can use the bits:
- Dim oTable As Table
- For Each oTable In ActiveDocument.Tables
- Next oTable
They should get you through all the tables in the doc.
The ScreenUpdating bit is also good, as it stops the screen flickering
madly while it's working. Don't forget to turn it back on at the bottom!
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
Public Sub DeleteEmptyRows()
Dim oTable As Table, oRow As Range, oCell As Cell, Counter As Long,
_
NumRows As Long, TextInRow As Boolean
' Turn off screen updating
Application.ScreenUpdating =3D False
' Specify which table you want to work on.
For Each oTable In ActiveDocument.Tables
=20
' Set a range variable to the first row's range
Set oRow =3D oTable.Rows(1).Range
NumRows =3D oTable.Rows.Count
=20
For Counter =3D 1 To NumRows
StatusBar =3D "Row " & Counter
TextInRow =3D False
For Each oCell In oRow.Rows(1).Cells
If Len(oCell.Range.Text) > 2 Then
'end of cell marker is actually 2 characters
TextInRow =3D True
Exit For
End If
Next oCell
If TextInRow Then
Set oRow =3D oRow.Next(wdRow)
Else
oRow.Rows(1).Delete
End If
Next Counter
Next oTable
' Turn screen updating back on
Application.ScreenUpdating =3D True
End Sub
=20
-----Original Message-----
From: austechwriter-bounce@xxxxxxxxxxxxx
[mailto:austechwriter-bounce@xxxxxxxxxxxxx] On Behalf Of Ilana Cohney
Sent: Thursday, 23 December 2004 10:17 AM
To: austechwriter@xxxxxxxxxxxxx
Subject: atw: Word macro - set table width
Hi all,
Would any of you happen to know how to write a macro that runs through a
document and sets all tables to a set width. I generate my Word XP=20
documents via AuthorIT and the tables come out all different widths=20
which looks terrible. I have tried writing a macro but my macro skills=20
are still in the very beginnning stages. So far my macro looks like
this:
Sub Fixed_width_Tables()
Dim myObject As Table
For Each myObject In ActiveDocument.Tables
With Selection.Tables(1)
.PreferredWidthType =3D wdPreferredWidthPoints
.PreferredWidth =3D CentimetersToPoints(13)
End With
Next
End Sub
My problem is that it works for one table and then stops! Any idea how=20
to tell it to continue on through the document and resize all tables.
Thanks for your help.
Ilana
**************************************************
To post a message to austechwriter, send the message to
austechwriter@xxxxxxxxxxxxxx
To subscribe to austechwriter, send a message to
austechwriter-request@xxxxxxxxxxxxx with "subscribe" in the Subject
field.
To unsubscribe, send a message to austechwriter-request@xxxxxxxxxxxxx
with "unsubscribe" in the Subject field.
To search the austechwriter archives, go to
www.freelists.org/archives/austechwriter
To contact the list administrator, send a message to
austechwriter-admins@xxxxxxxxxxxxx
**************************************************
**************************************************
To post a message to austechwriter, send the message to
austechwriter@xxxxxxxxxxxxxx
To subscribe to austechwriter, send a message to
austechwriter-request@xxxxxxxxxxxxx with "subscribe" in the Subject field.
To unsubscribe, send a message to austechwriter-request@xxxxxxxxxxxxx with
"unsubscribe" in the Subject field.
To search the austechwriter archives, go to
www.freelists.org/archives/austechwriter
To contact the list administrator, send a message to
austechwriter-admins@xxxxxxxxxxxxx
**************************************************
Other related posts: