Cycling through the Revisions collection

T

Tim

In Word 2000, I have a subroutine to compare two documents
and after comparing them, cycle through the collection and
print any page with revisions. The trouble is it seems to
get hung up on certain revisions when stepping through the
collection and Word stops responding. Debug.Print
statements show it gets hung up when the code tries to get
the page number of a particular revision. The bare bones
code, stripped down to its essence, is:

Public Sub CompAndPrint(strDoc1 As String, _
strDoc2 As String)

Dim objWordApp As Word.Application
Dim objRev As Word.Revision
Dim intLastPagePrinted As Integer
Dim intCurrentRevPage As Integer
Dim strPageList As String

Set objWordApp = New Word.Application

With objWordApp

.DisplayAlerts = wdAlertsNone

.Documents.Open FileName:=strDoc1, _
AddToRecentFiles:=False '1st document
.ActiveDocument.Compare Name:=strDoc2 'compare with 2nd

intLastPagePrinted = 0

For Each objRev In .ActiveDocument.Revisions

intCurrentRevPage = _
objRev.Range.Information(wdActiveEndPageNumber)

'check if added to page list yet
If intLastPagePrinted <> intCurrentRevPage Then
intLastPagePrinted = intCurrentRevPage
strPageList = strPageList & _
Format$(intLastPagePrinted) & ","
End If

Next objRev

strPageList = Left$(strPageList, _
-1 + Len(strPageList)) 'remove last ,

'now print
.PrintOut FileName:="", Range:=wdPrintRangeOfPages, _
Item:=wdPrintDocumentContent, Copies:=1, _
Pages:=strPageList, PageType:=wdPrintAllPages, _
Collate:=False, Background:=False, _
PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

'close, don't save
.ActiveDocument.Close wdDoNotSaveChanges

End With

objWordApp.Quit
Set objWordApp = Nothing

End Sub
 
W

Word Heretic

G'day "Tim" <[email protected]>,

ya know, I think I might just try a DoEvents after the compare and
before the loop. This might give Word enough time to actually do the
compare. If it stil fails, use an application.ontime command to delay
the execution of the second half (loopy part) for a few seconds to
give Word the time.

Best of luck mate!


Tim said:
In Word 2000, I have a subroutine to compare two documents
and after comparing them, cycle through the collection and
print any page with revisions. The trouble is it seems to
get hung up on certain revisions when stepping through the
collection and Word stops responding. Debug.Print
statements show it gets hung up when the code tries to get
the page number of a particular revision. The bare bones
code, stripped down to its essence, is:

Public Sub CompAndPrint(strDoc1 As String, _
strDoc2 As String)

Dim objWordApp As Word.Application
Dim objRev As Word.Revision
Dim intLastPagePrinted As Integer
Dim intCurrentRevPage As Integer
Dim strPageList As String

Set objWordApp = New Word.Application

With objWordApp

.DisplayAlerts = wdAlertsNone

.Documents.Open FileName:=strDoc1, _
AddToRecentFiles:=False '1st document
.ActiveDocument.Compare Name:=strDoc2 'compare with 2nd

intLastPagePrinted = 0

For Each objRev In .ActiveDocument.Revisions

intCurrentRevPage = _
objRev.Range.Information(wdActiveEndPageNumber)

'check if added to page list yet
If intLastPagePrinted <> intCurrentRevPage Then
intLastPagePrinted = intCurrentRevPage
strPageList = strPageList & _
Format$(intLastPagePrinted) & ","
End If

Next objRev

strPageList = Left$(strPageList, _
-1 + Len(strPageList)) 'remove last ,

'now print
.PrintOut FileName:="", Range:=wdPrintRangeOfPages, _
Item:=wdPrintDocumentContent, Copies:=1, _
Pages:=strPageList, PageType:=wdPrintAllPages, _
Collate:=False, Background:=False, _
PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

'close, don't save
.ActiveDocument.Close wdDoNotSaveChanges

End With

objWordApp.Quit
Set objWordApp = Nothing

End Sub

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 

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