Long tables in Word

O

Ove

When I'm using this code on a large table Word freezes and I have to
restart everything. The table is 90 pages long. When I'm using it on
smaller tables 20-30 pages, it's slow but works pretty good.

Set oTbl = ActiveDocument.Tables(1)
For iRow = oTbl.Rows.Count To 2 Step -1
With oTbl.Rows(iRow).Range
Set oRngDate = .Cells(2).Range
oRngDate.MoveEnd Unit:=wdCharacter, Count:=-1
If oRngDate.Text <> Format(Date, "dd.mm.yy") Then
.Font.Hidden = True
iCount = iCount + 1
End With

The idea is to print out a repost on records registrated today. Anyone
has any idea except changing to Access (we don't have it), or is Word
worthless on large tables?

Thanks
 
J

Jay Freedman

Hi, Ove,

For general information about handling large tables, see
http://www.mvps.org/word/FAQs/TblsFldsFms/FastTables.

For this specific job, see if this variation works faster/better:

Sub foo1()
Dim oTbl As Table
Dim oRow As Row
Dim strDate As String, strToday As String
Dim iCount As Long

strToday = Format(Date, "dd.mm.yy")

Application.ScreenUpdating = False

Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
strDate = oRow.Cells(2).Range.Text
strDate = Left(strDate, Len(strDate) - 2)

If strDate <> strToday Then
oRow.Range.Font.Hidden = True
iCount = iCount + 1
End If
Next oRow

Application.ScreenUpdating = True
MsgBox iCount & " rows hidden"
End Sub

If not, you might be better served by defining a character style in the
document (I called it Invisible) equal to Default Paragraph Style + Hidden,
and using this variation:

Sub foo2()
Dim oTbl As Table
Dim oRow As Row
Dim strDate As String, strToday As String
Dim iCount As Long

strToday = Format(Date, "dd.mm.yy")

Application.ScreenUpdating = False

Set oTbl = ActiveDocument.Tables(1)
For Each oRow In oTbl.Rows
strDate = oRow.Cells(2).Range.Text
strDate = Left(strDate, Len(strDate) - 2)

If strDate <> strToday Then
oRow.Range.Style = ActiveDocument.Styles("Invisible")
iCount = iCount + 1
End If
Next oRow

Application.ScreenUpdating = True
MsgBox iCount & " rows hidden"
End Sub
 
O

Ove

Hi
Thank you for replying.
Your code is working better than my first. But it still takes very
long time to print the reports. The report on 90 pages, takes like 10
minutes ++ before starting to print.
So I probably have to figure out other way of doing it. Maybe find
(Date today), select, copy and add to new document.

Thanks for you help!

Regards
Ove Malde
 

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