Getting Range of a Comment?

E

Ed

I'm using Word 2002. After trying to find a setting that would print only
reviewer's comments, AND the text commented on AND the page number of the
comment, I gave up and created a macro. In the macro, I got the Range of
the comment using Comment.Reference. As far as I can tell, though, this
contains only the closing bracket of the comment. I couldn't find a way to
locate the opening bracket and set a Range to the entire bracketed text.
Any suggestions?

Ed
 
K

Klaus Linke

Hi Ed,

You'd want to look what page Comment.Scope.Start is on.
The Scope property gives you the range of the commented text.

Greetings,
Klaus
 
B

Baher

here is the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub
 
B

Baher

heres the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub
 
K

Klaus Linke

Hi Baher,

The Index isn't really a fixed ID, but calculated on the fly, I guess.
With overlapping or identical comment scopes, it can be problematic to
predict which comment will get which index.
Also there seem to be bugs with the comments collection and tables.

Does the code work for you now, or do you still have issues with it?

Regards,
Klaus



Baher said:
here is the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub

Baher said:
Ed...thats exactly what i'm looking for too. Only diff is i dont want
the
page number but i'd like the comment ID that Word creates....i got the
following info but it didnt help me as much as i hoped....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k/html/wdcomnts.asp

can you post your macro? or email (e-mail address removed)

much appreciated!
 
B

Baher

Hey Klaus,

Yes the code does work. Our plan was to not add or delete comments in the
documents after the first pass so it wouldnt change the counter on the
comments. for the most part i get what i want but the range of text the
comment applies to if it has a carriage return in it puts that return in the
output. no big deal. its easier to get in excel that way rather than
copy/paste one by one. Thanks for the reply!

Klaus Linke said:
Hi Baher,

The Index isn't really a fixed ID, but calculated on the fly, I guess.
With overlapping or identical comment scopes, it can be problematic to
predict which comment will get which index.
Also there seem to be bugs with the comments collection and tables.

Does the code work for you now, or do you still have issues with it?

Regards,
Klaus



Baher said:
here is the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub

Baher said:
Ed...thats exactly what i'm looking for too. Only diff is i dont want
the
page number but i'd like the comment ID that Word creates....i got the
following info but it didnt help me as much as i hoped....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k/html/wdcomnts.asp

can you post your macro? or email (e-mail address removed)

much appreciated!

:

I'm using Word 2002. After trying to find a setting that would print
only
reviewer's comments, AND the text commented on AND the page number of
the
comment, I gave up and created a macro. In the macro, I got the Range
of
the comment using Comment.Reference. As far as I can tell, though,
this
contains only the closing bracket of the comment. I couldn't find a
way to
locate the opening bracket and set a Range to the entire bracketed
text.
Any suggestions?

Ed
 
B

Baher

just thought of something. can i ouput comments to excel directly? i think
i saw a post that said you can do it to text file then open in excel, but
either way i couldnt figure that out just yet. thanks!

Klaus Linke said:
Hi Baher,

The Index isn't really a fixed ID, but calculated on the fly, I guess.
With overlapping or identical comment scopes, it can be problematic to
predict which comment will get which index.
Also there seem to be bugs with the comments collection and tables.

Does the code work for you now, or do you still have issues with it?

Regards,
Klaus



Baher said:
here is the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub

Baher said:
Ed...thats exactly what i'm looking for too. Only diff is i dont want
the
page number but i'd like the comment ID that Word creates....i got the
following info but it didnt help me as much as i hoped....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k/html/wdcomnts.asp

can you post your macro? or email (e-mail address removed)

much appreciated!

:

I'm using Word 2002. After trying to find a setting that would print
only
reviewer's comments, AND the text commented on AND the page number of
the
comment, I gave up and created a macro. In the macro, I got the Range
of
the comment using Comment.Reference. As far as I can tell, though,
this
contains only the closing bracket of the comment. I couldn't find a
way to
locate the opening bracket and set a Range to the entire bracketed
text.
Any suggestions?

Ed
 
K

Klaus Linke

You can't copy/paste all comments in one go from the reviewing pane, but you
could from the (old) comments pane:
ActiveDocument.ActiveWindow.View.SplitSpecial=wdPaneComments

Or if you need to keep track of the index, you could write the index
followed by a tab and the comment text to a text file, and open that in
Excel (...which I take it is what you are doing already?).

Greetings,
Klaus


Baher said:
Hey Klaus,

Yes the code does work. Our plan was to not add or delete comments in the
documents after the first pass so it wouldnt change the counter on the
comments. for the most part i get what i want but the range of text the
comment applies to if it has a carriage return in it puts that return in
the
output. no big deal. its easier to get in excel that way rather than
copy/paste one by one. Thanks for the reply!

Klaus Linke said:
Hi Baher,

The Index isn't really a fixed ID, but calculated on the fly, I guess.
With overlapping or identical comment scopes, it can be problematic to
predict which comment will get which index.
Also there seem to be bugs with the comments collection and tables.

Does the code work for you now, or do you still have issues with it?

Regards,
Klaus



Baher said:
here is the code i found and modified:

Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "[" & cmt.Author & cmt.Index & "]" & " " &
cmt.Range.Text &
" Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s

End Sub

:

Ed...thats exactly what i'm looking for too. Only diff is i dont want
the
page number but i'd like the comment ID that Word creates....i got the
following info but it didnt help me as much as i hoped....

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k/html/wdcomnts.asp

can you post your macro? or email (e-mail address removed)

much appreciated!

:

I'm using Word 2002. After trying to find a setting that would
print
only
reviewer's comments, AND the text commented on AND the page number
of
the
comment, I gave up and created a macro. In the macro, I got the
Range
of
the comment using Comment.Reference. As far as I can tell, though,
this
contains only the closing bracket of the comment. I couldn't find a
way to
locate the opening bracket and set a Range to the entire bracketed
text.
Any suggestions?

Ed
 
K

Klaus Linke

Klaus Linke said:
You can't copy/paste all comments in one go from the reviewing pane, but
you could from the (old) comments pane:
ActiveDocument.ActiveWindow.View.SplitSpecial=wdPaneComments

BTW, if you copy/paste from that pane, you will likely loose the comment
markers.
But if you take the content into a string variable, myString=Selection.Text,
the string should contain a Chr(5) for each comment marker.

Klaus
 
B

Baher

klaus,

would you know how i could take out any linefeeds or returns in the
cmt.Scope.Text?

here is my code now...
Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "IP#[" & cmt.Author & cmt.Index & "]" & " " & cmt.Range.Text
& vbTab & "Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub
 
K

Klaus Linke

Hi Baher,

Line feeds are Chr(11), returns Chr(13) or vbCr.
You'll probably want to replace them with spaces:
Dim st as String
st=cmt.Scope.Text
st=Replace(st,Chr(11)," ")
st=Replace(st,vbCr," ")
Maybe replace any vbTab in cmt.Scope.Text with a space too, if there's the
possibility of tabs there?
st=Replace(st,vbTab," ")
and then clean up double spaces
st=Replace(st," "," ")
s = s & "IP#[" & cmt.Author & cmt.Index & "]" & _
" " & cmt.Range.Text & vbTab & "Text: " & st & vbCr

Greetings,
Klaus


Baher said:
klaus,

would you know how i could take out any linefeeds or returns in the
cmt.Scope.Text?

here is my code now...
Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "IP#[" & cmt.Author & cmt.Index & "]" & " " &
cmt.Range.Text
& vbTab & "Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub


Klaus Linke said:
BTW, if you copy/paste from that pane, you will likely loose the comment
markers.
But if you take the content into a string variable,
myString=Selection.Text,
the string should contain a Chr(5) for each comment marker.

Klaus
 
B

Baher

Perfect!

Thanks, Klaus.

Klaus Linke said:
Hi Baher,

Line feeds are Chr(11), returns Chr(13) or vbCr.
You'll probably want to replace them with spaces:
Dim st as String
st=cmt.Scope.Text
st=Replace(st,Chr(11)," ")
st=Replace(st,vbCr," ")
Maybe replace any vbTab in cmt.Scope.Text with a space too, if there's the
possibility of tabs there?
st=Replace(st,vbTab," ")
and then clean up double spaces
st=Replace(st," "," ")
s = s & "IP#[" & cmt.Author & cmt.Index & "]" & _
" " & cmt.Range.Text & vbTab & "Text: " & st & vbCr

Greetings,
Klaus


Baher said:
klaus,

would you know how i could take out any linefeeds or returns in the
cmt.Scope.Text?

here is my code now...
Sub DisplayComments()
Dim s As String
Dim cmt As Word.Comment
Dim doc As Word.Document
For Each cmt In ActiveDocument.Comments
s = s & "IP#[" & cmt.Author & cmt.Index & "]" & " " &
cmt.Range.Text
& vbTab & "Text: " & cmt.Scope.Text & vbCr
Next
Set doc = Documents.Add
doc.Range.Text = s
End Sub


Klaus Linke said:
You can't copy/paste all comments in one go from the reviewing pane,
but
you could from the (old) comments pane:
ActiveDocument.ActiveWindow.View.SplitSpecial=wdPaneComments

BTW, if you copy/paste from that pane, you will likely loose the comment
markers.
But if you take the content into a string variable,
myString=Selection.Text,
the string should contain a Chr(5) for each comment marker.

Klaus
 

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