Not sure what you're getting at here. Ranges and pages are not directly
related. The body of the document is one big range, from Start = 1 to
whatever. If page 20 starts at position 593, then Range(Start:593, End:=594)
will refer to the first character on page 20.
You don't need to select the range to check its characters. In the code
snippet you give, the Select statements are irrelevant, apart from the last
one.
You don't need to redefine the range each time you iterate your loop: you
can simply reset range's start and end properties:
MyRange.Start = pos
MyRange.End = pos + 1
You can use the MoveEndUntil method to find the character you want in one
go:
With ActiveDocument.Range(Start:=81, End:=81)
.MoveEndUntil oChar
.End = .End + 1
.Select
End with
> Hello,
> I am new to VBA with Word. Can someone tell me how I would select a certain
[quoted text clipped - 18 lines]
> Loop
> Set myRng = ActiveDocument.Range(Start:=81, End:=Pos)
John - 19 Dec 2004 03:20 GMT
Ok,
Thanks! But how can you tell what the starting character is for a given
page? In other words, how do you know what position page 20 starts at?
THANKS!
> Not sure what you're getting at here. Ranges and pages are not directly
> related. The body of the document is one big range, from Start = 1 to
[quoted text clipped - 48 lines]
>> Loop
>> Set myRng = ActiveDocument.Range(Start:=81, End:=Pos)
Jezebel - 19 Dec 2004 03:40 GMT
pStart = Selection.GoTo(What:=wdGoToPage, Name:="20").Start
> Ok,
> Thanks! But how can you tell what the starting character is for a given
[quoted text clipped - 54 lines]
> >> Loop
> >> Set myRng = ActiveDocument.Range(Start:=81, End:=Pos)
fumei - 30 Dec 2004 17:35 GMT
Well, if you need to know the actual integer of the first character of any
page, you must go there first. This is because "page" is a dynamic object.
So:
' go to whatever page - 20 in this example
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="20"
' uses the pre-defined bookmark "page" to get the Range.Start
' this is a Long Integer
MsgBox ActiveDocument.Bookmarks("\page").Range.Start
So, for example, if for some reason or other, you wanted to know how many
characters were on a specific page:
Dim lngStart As Long
Dim lngEnd As Long
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="20"
lngStart = ActiveDocument.Bookmarks("\page").Range.Start
lngEnd = ActiveDocument.Bookmarks("\page").Range.End
MsgBox "This page starts at character number " & _
lngStart & " and ends at " & _
lngEnd & ", for a total of " & _
(lngEnd - lngStart) & " characters, including spaces."
> pStart = Selection.GoTo(What:=wdGoToPage, Name:="20").Start
>
[quoted text clipped - 59 lines]
> > >> Loop
> > >> Set myRng = ActiveDocument.Range(Start:=81, End:=Pos)