How to determine cursor position within a document

R

Roderick O'Regan

I have to create a document which is divided into "chapters".

Each of these "chapters" starts with a numbered style - say SpecialH1
and therefore occurs once only in each chapter.

Within each chapter the user can add sections at random and as many as
needed if they require to turn pages landscape for maps, diagrams and
the like.

If the user is in "chapter" 2 I can allow him to add a new chapter
before the existing chapter 2 (which then becomes chapter 3).

However, if the user's cursor is anywhere within chapter one,
irrespective of the number of sections it may contain I must prevent
them from adding a new chapter ***before*** chapter 1.

At present I'm using the following to tell me in which section the
cursor is in:
thisSection = Selection.Information(wdActiveEndSectionNumber)
This works OK provided there are a finite number of sections within
chapter 1 and by manipulating the information I can prevent users from
inserting a chapter before number 1.

The problem arises when the sections within chapter 1 are varied,
perhaps 2 or 4 or whatever.

Is there a way, perhaps, of selecting the numbered style at the top of
each chapter and identifying at which number it is? If it was at 1
then prevent user from adding another one before it.

Can anyone point me in the right direction, please? My head is going
into "fuzzy mode" trying to identify the way around this!

Regards

Roderick
 
J

Jean-Guy Marcil

Roderick O'Regan was telling us:
Roderick O'Regan nous racontait que :
I have to create a document which is divided into "chapters".

Each of these "chapters" starts with a numbered style - say SpecialH1
and therefore occurs once only in each chapter.

Within each chapter the user can add sections at random and as many as
needed if they require to turn pages landscape for maps, diagrams and
the like.

If the user is in "chapter" 2 I can allow him to add a new chapter
before the existing chapter 2 (which then becomes chapter 3).

However, if the user's cursor is anywhere within chapter one,
irrespective of the number of sections it may contain I must prevent
them from adding a new chapter ***before*** chapter 1.

At present I'm using the following to tell me in which section the
cursor is in:
thisSection = Selection.Information(wdActiveEndSectionNumber)
This works OK provided there are a finite number of sections within
chapter 1 and by manipulating the information I can prevent users from
inserting a chapter before number 1.

The problem arises when the sections within chapter 1 are varied,
perhaps 2 or 4 or whatever.

Is there a way, perhaps, of selecting the numbered style at the top of
each chapter and identifying at which number it is? If it was at 1
then prevent user from adding another one before it.

Can anyone point me in the right direction, please? My head is going
into "fuzzy mode" trying to identify the way around this!

You mean something like this:

'_______________________________________
Sub CheckChapterNumber()

Dim curRge As Range

With Selection
Set curRge = .Range
With .Find
.Forward = False
.Style = "Heading 1"
.Execute
End With
With .Range.ListFormat
If .ListValue = 1 Then
MsgBox "You cannot add a section before Chapter " _
& .ListValue & ".", vbExclamation, "Cancelled"
Else
MsgBox "You can add a section before Chapter " _
& .ListValue & ".", vbExclamation, "Go Ahead"
End If
End With
End With

curRge.Select

Application.Browser.Target = wdBrowsePage

End Sub
'_______________________________________

??

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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