select "hard page" code?

G

gil

Hi All,

Is there code to select the "hard page" the cursor is on without using the
wildcard find function? By hard page, I mean the portion the cursor is in
between two hard page breaks OR one hard page break and the end of the
document.

tia

Gil

http://www.TenSecondMedicalRecord.com electronic medical records programs
since 1990, MS Word based since 1996
 
T

Tony Jollans

Selection.Bookmarks("\page").Select

Works with 'soft' page breaks as well. if you explicitly want hard page
breaks and end of document only it's a little more complicated.
 
G

gil

Ahhh, ... I think I found it.

Application.Run "ExtendSelection"
With Selection.Find
.ClearFormatting
.Text = "^m"
.Forward = False
.Execute
End With
'The ExtendSelection can then be turned off with:
' Selection.EscapeKey

Gil
 
T

Tony Jollans

Hi Gil,

Rather than the Run, it would be better to use Selection.Extend

That said, your code will extend the selection back to the previous hard
page break if there is one so I'm still unclear as to your precise
requirements - although you are probably on the right road.
 
G

gil

Yep, yer right. The idea didn't get all the way there. But I think the
following code might get it.

With Selection.Find
.ClearFormatting
.Execute FindText:="^m", Forward:=True
' where ^m is a hard page break
.Wrap = wdFindStop
If .Found = True Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="^m was found"
Else
Selection.TypeText Text:="^m was NOT found"
End If
End With


Or, in more extended fashion, ...

Sub selectHardPage()
'
' selectHardPage macro
'
'
With Selection.Find
.ClearFormatting
.Execute FindText:="^m", Forward:=True
.Wrap = wdFindStop
If .Found = True Then
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' Selection.TypeText Text:="^m was found"
' Application.Run "ExtendSelection"
Selection.Extend
With Selection.Find
.ClearFormatting
.Text = "^m"
.Forward = False
.Execute
End With

Else
' Selection.TypeText Text:="^m was NOT found"
Selection.EndKey Unit:=wdStory
' Application.Run "ExtendSelection"
Selection.Extend
With Selection.Find
.ClearFormatting
.Text = "^m"
.Forward = False
.Execute
End With

End If
End With
End Sub

Cheers,
Gil
 
T

Tony Jollans

Hi Gil,

I haven't tried it but from a quick look that appears as though it will do
something close to what you want. If it doesn't, do come back.

You might find it easier though to do it like this (untested):

SavePoint = Selection.Start
Selection.MoveStartUntil Chr(12), wdbackward
If selection.start = SavePoint then ' Start has not moved
If SavePoint > ActiveDocument.range.Start then ' NOt at start of
document
If activedocument.range(savepoint -1, savepoint).Text <> Chr(12)
Then ' No previous hard page
Selection.homekey wdstory ' start of document
end If
End If
End if


SavePoint = Selection.End
Selection.MoveendUntil Chr(12), wdForward
If selection.End = SavePoint then ' End has not moved
If SavePoint < ActiveDocument.range.End then ' NOt at end of
document
If activedocument.range(savepoint, savepoint + 1).Text <>
Chr(12) Then ' No next hard page
Selection.Extend
Selection.EndKey wdstory ' End of Document
end If
End If
End if
 
G

gil

Thanks Tony, I'll play with it.
:)
Gil

Tony Jollans said:
Hi Gil,

I haven't tried it but from a quick look that appears as though it will do
something close to what you want. If it doesn't, do come back.

You might find it easier though to do it like this (untested):

SavePoint = Selection.Start
Selection.MoveStartUntil Chr(12), wdbackward
If selection.start = SavePoint then ' Start has not moved
If SavePoint > ActiveDocument.range.Start then ' NOt at start of
document
If activedocument.range(savepoint -1, savepoint).Text <>
Chr(12)
Then ' No previous hard page
Selection.homekey wdstory ' start of document
end If
End If
End if


SavePoint = Selection.End
Selection.MoveendUntil Chr(12), wdForward
If selection.End = SavePoint then ' End has not moved
If SavePoint < ActiveDocument.range.End then ' NOt at end of
document
If activedocument.range(savepoint, savepoint + 1).Text <>
Chr(12) Then ' No next hard page
Selection.Extend
Selection.EndKey wdstory ' End of Document
end If
End If
End if
 
G

gil

Hey Tony !

Thank You Thank You Thank You :) :)

The earlier code would work once when the last page was to be selected, then
not work again unless the document was closed and reopened. Around and
around, twisting me into a knot. ;)

Your code works great. It's an intro to me for selection.start and
savepoint items. Probably a lot better than using text strings in the
document itself, then search find to relocate them.

:)
Happy Camper,
Gil
 

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