Is there a faster way to do this?

G

Garbunkel

This sub lets the user input a date & then proceeds to list all of the
Insert/Delete/Replace chnages that have been made a Microsoft Word Document
since that date. However, this takes a long time to complete, even with
small documents & with large docs, it takes a prohibitive amount of time.

The results are listed in a Word Document, with a tab printed in between the
"columns" (no table was used, as I found that using a table for the output
made this run even slower).

Does anyone know of a more effiicient way to tally up the differences?

Here's the code I have so far & thanks in advance!

Sub TrackByDate()
Dim srcDoc As Document, destDoc As Document
Dim oRev As Revision
Dim strCkDate As String
Dim ChangeTxt As String
Dim FileName As String
Dim CkDate As Date
Dim RevType As Variant
Dim nRows As Long

RevType = Array("NoRevision", "Insert", "Delete", _
"Property", "ParagraphNumber", "DisplayField", _
"Reconcile", "Conflict", "Style", "Replace", _
"ParagraphProperty", "TableProperty", _
"SectionProperty", "StyleDefinition")


strCkDate = InputBox$("Enter date (MM/DD/YYYY) to find all changes made
since:")
If strCkDate = "" Then Exit Sub
If Not IsDate(strCkDate) Then Exit Sub

CkDate = CDate(strCkDate)

Set srcDoc = ActiveDocument
Set destDoc = Documents.Add
destDoc.PageSetup.Orientation = wdOrientLandscape

destDoc.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Text = "Revisions in " & srcDoc.FullName

nRows = 1

destDoc.Range.Text = "Revisions in " & _
srcDoc.FullName & " since " & strCkDate & _
vbCr & vbCr & "Date" & " " & " " & "Time" & " " &
vbTab _
& "Page" & vbTab & "Line" & vbTab & "Change" & vbTab & "Text" & vbCr &
vbCr


For Each oRev In srcDoc.Revisions
nRows = nRows + 1

If CDate(Left$(Format(oRev.Date, "MM/DD/YYYY"), 10)) _
= CkDate Then

If (RevType(oRev.Type) = "Insert" Or _
RevType(oRev.Type) = "Delete" Or RevType(oRev.Type) = "Replace")
Then

ChangeTxt = oRev.Range.Text

ChangeTxt = Replace(ChangeTxt, vbCr, " ")
ChangeTxt = Replace(ChangeTxt, vbLf, " ")
ChangeTxt = Replace(ChangeTxt, vbCrLf, " ")

destDoc.Range.InsertAfter _
oRev.Date & " " & vbTab & _
oRev.Range.Information(wdActiveEndAdjustedPageNumber) & vbTab
& _
oRev.Range.Information(wdFirstCharacterLineNumber) & vbTab & _
RevType(oRev.Type) & vbTab & " " & ChangeTxt & vbCr

End If
End If
Next oRev
End Sub
 
J

Jonathan West

Garbunkel said:
This sub lets the user input a date & then proceeds to list all of the
Insert/Delete/Replace chnages that have been made a Microsoft Word
Document
since that date. However, this takes a long time to complete, even with
small documents & with large docs, it takes a prohibitive amount of time.

The results are listed in a Word Document, with a tab printed in between
the
"columns" (no table was used, as I found that using a table for the output
made this run even slower).

Does anyone know of a more effiicient way to tally up the differences?

I don't see that you can do all that much about the part of the code that
cycles through the revisions. But you can speed things up in terms of
writing out the results. Instead of writing each result to the new document
as you generate it, build up a long string in memory, and then write the
whole thing out in one go at the end.

Now, conventional string concatenation using the & operator can get slow
when you are dealing with long strings, so a better solution is to use Karl
Peterson's CStringBuilder class. The code and description is available for
free from here

http://vb.mvps.org/samples/project.asp?id=StrBldr
 
G

Garbunkel

Thanks Jonathan! So far, what I've implemented has helped. A lot of good
info.

- Michael
 

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