Get page number of range?

M

Matthew Leingang

Hello,

I'm reviewing and making comments on a number of long documents. The client
wants the comments in a separate document, though, so I thought I'd write a
macro to extract comments.

I want something like:

Page 2, Paragraph 3
This is a brilliant insight!

Page 4, Paragraph 5
Actually, this is false.

And so on...

So far I've got this:

--------
Public Sub CopyComments()

Dim i As Integer
Dim curDoc As Document
Dim newDoc As Document
Dim rng As Range
Dim cmt As Comment

Set curDoc = ActiveDocument
Set newDoc = Documents.Add
Set rng = newDoc.Range


For i = 1 To curDoc.Comments.Count
Set cmt = curDoc.Comments(i)
rng.InsertAfter ("PAGE: " & cmt.Scope.Information(wdActiveEndPageNumber)
& vbCr)
rng.InsertAfter ("SCOPE:" & cmt.Scope & vbCr)
rng.InsertAfter ("COMMENT: " & cmt.Range & vbCr & vbCr)

Next i
End Sub
--------

I saw the Information call used somewhere to get the page of the cursor
selection, so I thought it would adapt. Instead,
cmt.Scope.Information(wdActiveEndPageNumber) returns -1.

This is my first experience with VBA. Any clues?

TIA,
Matt
 
H

Helmut Weber

Hi Matthew,

your code works perfectly here and now.
Which doesn't help you much, of course, I'm sorry.

In some versions of Word higher than 97
Selection.Information(wdFirstCharacterLineNumber)
returns -1, unless views, e.g. normal view versus print view,
where not switched to and fro before.

Maybe there are similar effects with wdActiveEndPageNumber.

At least you know, it has nothing to do with your code.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
M

Matthew Leingang

Dear Helmut,

Thanks for checking. I probably should have mentioned that I'm using Word
2004 for Mac. Maybe that's the problem.

I was able to work around by selecting each range, then getting the
selection's information:

Set cmt = curDoc.Comments(i)
cmt.scope.Select
rng.InsertAfter ("Page " & Selection.Information(wdActiveEndPageNumber)
& ", ")
rng.InsertAfter ("line " &
Selection.Information(wdFirstCharacterLineNumber) & ": ")

I know, originally I had wanted to give the paragraph number but this is
just as good.

Yours,
Matthew Leingang <-- ein deutsche Name. Meine Vorfahren kommen aus der
Pfalz
 

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