PDA

View Full Version : Identifying the exact location of Comments or Revisions



bbqq021
04-30-2013, 11:11 PM
I have been trying to write some code for some time, i'm into the final stages or ironing out the minor problems. I have one really annoying glitch that i wouldn't mind some help on.

Essentially, my colleagues will review word documents and make changes (additions or deletions only) using track changes. On the original text which is deleted or a for a new addition. They will then write a comment explaining why they are making the changes. The code will then extract all the comments followed by all the revisions, put them in a table and then sort them based on the page number and line number.

This works fine apart from when the comment overlaps onto 2 pages. Word reports the position of the comment using the last character whereas it reports the position of the revisions using the initial character meaning the comment is on page 13 however the revision which was immediately after the comment is actually reported to be on page 12.

I am not sure if there are any slicker ways of doing it however I was thinking something along the lines of:

Test to see if the first and last character of a particular range (the comment was on the same page).

If oDoc.Comments(C).Scope.range (start) = oDoc.Comments(C).Scope.range (end) then

Do normal code

Else oDoc.Comments(C).Scope.Information(wdActiveEndAdjustedPageNumber) - 1

As you can see I am not very familiar with the syntax. Frosty tells me I have to collapse the range however this does not mean a lot to me.

Any suggestions would be really appreciated.

Thanks
Will

gmaxey
05-01-2013, 05:00 AM
Something like:

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oComment As Word.Comment, oRngSS As Word.Range, oRngSE As Word.Range
Set oComment = ActiveDocument.Comments(1)
Set oRngSS = oComment.Scope
Set oRngSE = oComment.Scope
oRngSS.Collapse wdCollapseStart
oRngSE.Collapse wdCollapseEnd
If oRngSS.Information(wdActiveEndPageNumber) = oRngSE.Information(wdActiveEndPageNumber) Then
MsgBox "Commented text is on the same page."
Else
MsgBox "Commented text is spans two or more pages"
End If
End Sub

bbqq021
05-01-2013, 06:48 PM
Perfect, thanks Greg here is my final code which makes a few tweaks to reduce the page number by the correct amount, incase it runs over 3 pages.

'This text tests for comments spanning more than 1 page and makes the correction to the wdactiveendpagenumber
'thanks to Greg Maxey from VBAExpress Forum

Set oComment = oDoc.Comments(C)
Set oRngSS = oComment.Scope
Set oRngSE = oComment.Scope


oRngSS.Collapse wdCollapseStart
oRngSE.Collapse wdCollapseEnd

If oRngSS.Information(wdActiveEndPageNumber) = oRngSE.Information(wdActiveEndPageNumber) Then
GoTo restart1
Else
PageCorr = oRngSE.Information(wdActiveEndPageNumber) - oRngSS.Information(wdActiveEndPageNumber)
.Cells(2).Range.Text = oDoc.Comments(C).Scope.Information(wdActiveEndAdjustedPageNumber) - PageCorr
End If
GoTo restart2

restart1:
'Page number
.Cells(2).Range.Text = oDoc.Comments(C).Scope.Information(wdActiveEndAdjustedPageNumber)
restart2:

bbqq021
05-01-2013, 06:49 PM
Perfect, thanks Greg here is my final code which makes a few tweaks to reduce the page number by the correct amount, incase it runs over 3 pages.


'This text tests for comments spanning more than 1 page and makes the correction to the wdactiveendpagenumber
'thanks to Greg Maxey from VBAExpress Forum

Set oComment = oDoc.Comments(C)
Set oRngSS = oComment.Scope
Set oRngSE = oComment.Scope


oRngSS.Collapse wdCollapseStart
oRngSE.Collapse wdCollapseEnd

If oRngSS.Information(wdActiveEndPageNumber) = oRngSE.Information(wdActiveEndPageNumber) Then
GoTo restart1
Else
PageCorr = oRngSE.Information(wdActiveEndPageNumber) - oRngSS.Information(wdActiveEndPageNumber)
.Cells(2).Range.Text = oDoc.Comments(C).Scope.Information(wdActiveEndAdjustedPageNumber) - PageCorr
End If
GoTo restart2

restart1:
'Page number
.Cells(2).Range.Text = oDoc.Comments(C).Scope.Information(wdActiveEndAdjustedPageNumber)
restart2: