return which chapter from the current cursor

A

Associates

Hi,

I wonder if there is a way to find out which chapter in the report the
current insertion point is at in VBA. Each chapter is ended with a section
break. I was trying to find the code that would return which chapter the
insertion point is currently at

For example: i am in the middle of writing for Chapter 3 as follows

Chapter 3 Internal Museum
blah blah blah

if my insertion point cursor is at the end of "blah" or anywhere within that
chapter, it will return 3.

Your help would be greatly appreciated.

Thank you in advance
 
G

Graham Mayor

If each chapter is a section then you can get the current section number
which will be the Chapter number

MsgBox "Chapter " & Selection.Information(wdActiveEndSectionNumber)


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Associates

Thank you Graham for your reply.

Yes, that's what i'm after.

If i could ask another similar question, is it possible to bring the
insertion point to the end of a section (e.g. [Here] as shown below)next to
the section break.

For example, Monitoring Consumption is a Heading 1

Monitoring Consumption
blah blah...
.....
.....

[here]---------------Section Break (Next Page)-------------------

The aim here is to allow user to insert another Heading to the document via
VBA. Hence, if i could find a way to move the cursor to that spot just before
the section break, another new Heading section can be inserted. I could use
bookmarks but it requires the bookmarks to be pre-determined beforehand but
couldn't do that as this document is generated from our customised template.

Hope i don't confuse you with my explanation.

Thank you in advance
 
G

Graham Mayor

With Selection
.GoTo What:=wdGoToBookmark, name:="\Section"
.Collapse Direction:=wdCollapseEnd
.MoveLeft
End With

If you want the cursor *after* the section break remove the MoveLeft line

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Thank you Graham for your reply.

Yes, that's what i'm after.

If i could ask another similar question, is it possible to bring the
insertion point to the end of a section (e.g. [Here] as shown
below)next to the section break.

For example, Monitoring Consumption is a Heading 1

Monitoring Consumption
blah blah...
....
....

[here]---------------Section Break (Next Page)-------------------

The aim here is to allow user to insert another Heading to the
document via VBA. Hence, if i could find a way to move the cursor to
that spot just before the section break, another new Heading section
can be inserted. I could use bookmarks but it requires the bookmarks
to be pre-determined beforehand but couldn't do that as this document
is generated from our customised template.

Hope i don't confuse you with my explanation.

Thank you in advance

Graham Mayor said:
If each chapter is a section then you can get the current section
number which will be the Chapter number

MsgBox "Chapter " & Selection.Information(wdActiveEndSectionNumber)


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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