Go to closest editable area

D

dan.KSU

I have a template in Word 2003 that uses partion protection. Certain
areas of the doc have full edit capabilities while others are not
editable.

What I want to do is anytime the user clicks or selects inside a
protected area, I want it to move their cursor to the closes or next
editable area.

I have found very little on the events that drive the Protection Task
Pane. This is were I think the needed event resides.

All help is welcomed and appreciated!

Cheers,

Daniel Stevens
 
S

Shauna Kelly

Hi Daniel

myRange.GoToEditableRange(wdEditorCurrent) will move the selection to the
next editable range.

But Word doesn't expose any events related to areas of the document that are
protected. And, Word does not expose any events that fire when the user
moves the cursor by typing or by using the arrow keys. So on the face of it
there's no way to detect when a user moves into or out of an unprotected
region.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
T

Tony Jollans

It is true that Word does not expose any events that fire when the user
moves the cursor by typing but ...

... the WindowSelectionChange Event does fire when the user moves the
cursor with the arrow keys or clicks somewhere with the mouse so that can
catch a lot - probably everything you want to.

Try something like this:

Private Sub wd_WindowSelectionChange(ByVal Sel As Selection)

Dim UserPos As Range
Dim EditablePos As Range
Set UserPos = Selection.Range.Duplicate
Set EditablePos = UserPos.GoToEditableRange
If UserPos.Start > EditablePos.End Then
' tried to select past last range - just go to beginning of it
UserPos.Start = EditablePos.Start
UserPos.End = EditablePos.Start
Else
' If selection starts before an editable range move the start to the
start of that range
' If the end is also before the start move end to the start as well
' If the end is after the end of the editable range pull it back in,
else leave it alone
If UserPos.Start < EditablePos.Start Then
UserPos.Start = EditablePos.Start
If UserPos.End < EditablePos.Start Then
UserPos.End = EditablePos.Start
ElseIf UserPos.End > EditablePos.End Then
UserPos.End = EditablePos.End
Else
End If
Else
' Selection already starts in an editable range - leave it alone
' If the end is after the end of the editable range pull it back
in, else leave it alone
If UserPos.End > EditablePos.End Then
UserPos.End = EditablePos.End
End If
End If
End If
' Select the amended range
UserPos.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