Test if a selection ranges to the end of document

R

Raphael Goubet

Hi,

A macro I'm writing includes the insertion of a section break at the
end of a selection:

ActiveDocument.Range(Start:=Selection.End,
End:=Selection.End).InsertBreak _
Type:=wdSectionBreakContinuous

Now, this will fail if the selection ranges to the very last position
in the document (the last, unerasable carriage return that appears
when hidden characters are shown), since a section break cannot be
inserted after the last character of the document.

So, I have to test that the selection does not go that far, as it
would is the user selects with shift-ctrl-End. Checking Selection.End
is useless, since the value of that property is unpredictable. If the
selection stops earlier, it's OK, otherwise, I'll insert my section
break at Selection.End-1.

How can I do it?

Thanks in advance.

Raph
 
P

Peter Hewett

Hi Raphael Goubet

This should do what you want!:

Public Sub InsertSB()
With Selection
If .End = ActiveDocument.Content.End Then
.End = .End - 1
End If
ActiveDocument.Range(.End, .End).InsertBreak _
wdSectionBreakContinuous
End With
End Sub

HTH + Cheers - Peter


(e-mail address removed) (Raphael Goubet), said:
 

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