Reply
 
Thread Tools Display Modes
  #1   Report Post  
Stephen Gray
 
Posts: n/a
Default ClearFormatting get's slower and slower

To speed up a Word report ( using VB ) I'm trying to get a table per
page rather then one big table as they have previously. The table has
over 11,000 lines on it so it gets slower and slower. I=E2=80=99ve managed
to create one table per page ( which speeds up the report a lot ) but
the problem that I need to apply the clearFormatting to each row in
order to get it=E2=80=99s correct size ( so I can see if I need a new table
or not ). Previously the developer was able could do this for the
whole table but now I have to do it on a row my row basis. Below is
one a routine that they used previously on the table. The problem is
that this call gets slower and slower, even though I=E2=80=99m working on
only one row at a time. That is if I run the code for the first table
it runs through about 10 rows per second but if I say apply it to table
20 ( on page 20 ) it then only handles 1 possibly 2 a second.

I also tried using RegExp to do the removal for me which was fast but
sadly it removed the formatting =EF=81=8B

Any help would be appreciated !

Private Sub mpTrimRow(ByVal oRow As Word.Row)
Const cProcedure As String =3D "mpTrimRow"
On Error GoTo Handler

With oRow.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text =3D "^p" ' remove surplus CR
.Replacement.text =3D ""
.Forward =3D True
' .Wrap =3D wdFindContinue ' 12/05/03
.Wrap =3D wdFindStop
.Format =3D False
.MatchCase =3D False
.MatchWholeWord =3D False
.MatchWildcards =3D False
.MatchSoundsLike =3D False
.MatchAllWordForms =3D False
.Execute Replace:=3DwdReplaceAll
End With

With oRow.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text =3D "\{*\}" ' remove formatting commands using wildcard
.Replacement.text =3D ""
.Forward =3D True
' .Wrap =3D wdFindContinue ' rw 12/05/03
.Wrap =3D wdFindStop
.Format =3D False
.MatchCase =3D False
.MatchWholeWord =3D False
.MatchWildcards =3D True ' must be true to find wildcard
.MatchSoundsLike =3D False
.MatchAllWordForms =3D False
.Execute Replace:=3DwdReplaceAll
End With


Handler:
Throw Err, cMODULE, cProcedure
Exit Sub
End Sub

  #2   Report Post  
Klaus Linke
 
Posts: n/a
Default

Hi Stephen,

Do you really need to search row by row instead of table by table? Or maybe
even the whole document (since the paragraph marks between tables can't be
deleted with your Find/Replace anyway)?

Apart from that: Your code for calling mpTrimRow (which isn't shown) might
be culpable for the slow-down, too, say if you used "For i = 1 to
someTable.Rows.Count ".

If you really need to do it the way you are currently doing it, an
"ActiveDocument.UndoClear" after each replacement might help... but you
should make sure you have backed-up the file since Undo won't work any more.

My feeling is: If none of your tables span several pages when you start the
macro, and with less than 100 pages, all the replacements you're doing
together shouldn't need to take more than a very few seconds.

Regards,
Klaus


"Stephen Gray" schrieb im Newsbeitrag
oups.com...
To speed up a Word report ( using VB ) I'm trying to get a table per
page rather then one big table as they have previously. The table has
over 11,000 lines on it so it gets slower and slower. I've managed
to create one table per page ( which speeds up the report a lot ) but
the problem that I need to apply the clearFormatting to each row in
order to get it's correct size ( so I can see if I need a new table
or not ). Previously the developer was able could do this for the
whole table but now I have to do it on a row my row basis. Below is
one a routine that they used previously on the table. The problem is
that this call gets slower and slower, even though I'm working on
only one row at a time. That is if I run the code for the first table
it runs through about 10 rows per second but if I say apply it to table
20 ( on page 20 ) it then only handles 1 possibly 2 a second.

I also tried using RegExp to do the removal for me which was fast but
sadly it removed the formatting ?

Any help would be appreciated !

Private Sub mpTrimRow(ByVal oRow As Word.Row)
Const cProcedure As String = "mpTrimRow"
On Error GoTo Handler

With oRow.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "^p" ' remove surplus CR
.Replacement.text = ""
.Forward = True
' .Wrap = wdFindContinue ' 12/05/03
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With

With oRow.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "\{*\}" ' remove formatting commands using wildcard
.Replacement.text = ""
.Forward = True
' .Wrap = wdFindContinue ' rw 12/05/03
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True ' must be true to find wildcard
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With


Handler:
Throw Err, cMODULE, cProcedure
Exit Sub
End Sub


  #3   Report Post  
Stephen Gray
 
Posts: n/a
Default

Hi Klaus,

Thanks for responding. Previously the developer had one massive table,
with the headers duplicated on each page and then he/she applied the
search and replace to the whole document it was fast. However the
table creation was very very slow ( + 8 hours ! ). This is a fairly
old system and they way they do it is export the data from Crystal in a
Word format. The word document has the text, a number of formatting
codes in and also has text coloured and bold. The app then takes that
document, creates a new document, formats it with the crystal codes
specified ( via translation code ) and then at the end it removes the
formatting chars and any carriage return codes. I=E2=80=99ve changed the
code to only produce one table per page, and copy the header rows from
the first table and it takes the time down to 20 mins, if I don=E2=80=99t
apply the search and replace. If I do it takes the total time to 2
hours! Sadly I do have to do it row by row as removing the formatting
does make the rows smaller and I have to work out if a new row will go
onto the next page, if it does remove it and create a table instead
with one row. The call to mpTrimRow is called after the row has been
created.

Using a simple search and replace in VB takes no time at all either on
a row by row but if I do that it for some reason looses any formatting
applied ( as you can see I don=E2=80=99t know that much about Word =EF=81=
=8B )

As a side point the word document produced from Crystal has in it
11,000+ Paragraphs ( which get copied as rows in tables in the new
document ). The original developer was going through each paragraph
via the index and that alone was taking 40 minutes or so ! I changed
it to a For Each and it went down to 20 seconds.

Thanks again Klaus, or anyone, for any pointers you can give.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the Properties of a file is significantly slower than open cc Microsoft Word Help 1 June 24th 05 01:35 AM


All times are GMT +1. The time now is 10:31 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"