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

Re: How to determine cursor position within a document by Jean-Guy

Jean-Guy
Tue May 10 09:15:18 CDT 2005

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
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org




Re: How to determine cursor position within a document by Roderick

Roderick
Tue May 10 10:38:23 CDT 2005

BRILLIANT! Sorry - I just had to shout there...

Merci, Jean-Guy.

Roderick

On Tue, 10 May 2005 10:15:18 -0400, "Jean-Guy Marcil"
<no-spam@leaveme.alone> wrote:

>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
>'_______________________________________
>
>??