Get positions of paragraphs in word 2007? seems different with 200

Q

qnever

I want to get the position relative to page of a paragraph in word 2007.
However, I can only get the correct positions of paragraphs in the first
page. But with the same macros in word 2003, I got all positions of
paragraphs in every page correctly. Below is my macro.
Thanks!

Sub Test()
Dim i As Paragraph, myInfo As String, myRange As Range
For Each i In ActiveDocument.Content.Paragraphs
If i.OutlineLevel < 10 And i.Range.Information(wdWithInTable) =
False Then
myInfo = myInfo &
i.Range.Information(wdVerticalPositionRelativeToPage) & " "
End If
Next
MsgBox myInfo
End Sub
 
J

Jean-Guy Marcil

qnever was telling us:
qnever nous racontait que :
I want to get the position relative to page of a paragraph in word
2007. However, I can only get the correct positions of paragraphs in
the first page. But with the same macros in word 2003, I got all
positions of paragraphs in every page correctly. Below is my macro.
Thanks!

Sub Test()
Dim i As Paragraph, myInfo As String, myRange As Range
For Each i In ActiveDocument.Content.Paragraphs
If i.OutlineLevel < 10 And i.Range.Information(wdWithInTable) =
False Then
myInfo = myInfo &
i.Range.Information(wdVerticalPositionRelativeToPage) & " "
End If
Next
MsgBox myInfo
End Sub

It seems to be a bug to me.

With 2007, I tried this simple macro with the third paragraph down the
second page being selected:
---------
Sub Test_1()

Dim oO As Range

Set oO = Selection.Range.Paragraphs(1).Range
MsgBox oO.Information(wdVerticalPositionRelativeToPage)

End Sub
---------

But the code returned the position of the first paragraph on the page.

This code is a workaround, but you shouldn't need such kludgy workarounds...
---------
Sub Test()

Dim i As Long
Dim myInfo As String
Dim myRange As Range
Dim rgeSave As Range

Set rgeSave = Selection.Range

Application.ScreenUpdating = False

For i = 1 To ActiveDocument.Range.Paragraphs.Count
Set myRange = ActiveDocument.Range.Paragraphs(i).Range
With myRange
If .Paragraphs(1).OutlineLevel <= 10 And .Information(wdWithInTable)
= False Then
.Select
.Collapse wdCollapseStart
myInfo = myInfo &
Selection.Information(wdVerticalPositionRelativeToPage) & " "
End If
End With
Next

MsgBox myInfo

Application.ScreenRefresh
Application.ScreenUpdating = True

rgeSave.Select

End Sub
 

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