Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Move cursor to end of table of contents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TimDouglas - 01 Aug 2006 14:46 GMT
Hi all,

I have a macro which adds extra text into the table of contents, but for it
to work correctly, the cursor needs to be placed at the end of the TOC.  Is
there a way I can get word to place the cursor there automatically, rather
than making the user do it?

Thanks a lot,

TimDouglas
Jonathan West - 01 Aug 2006 15:00 GMT
> Hi all,
>
[quoted text clipped - 4 lines]
> there a way I can get word to place the cursor there automatically, rather
> than making the user do it?

Don't use the Selection object at all. Word instead with a Range object,
which is very much like the selection except that you can define as many of
them as you like, and the cursor doesn't move around when you change them.
Just about every element in a Word document has a Range property. So, for
instance, you could do this

Dim oRange as Range
Set oRange = ActiveDocument.TablesOfContents(1).Range

Now, oRange is "marking" the whole of the table of contents. You can use the
InsertAfter method to insert text after the table of contents, or
InsertBefore to insert text before it.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Jean-Guy Marcil - 01 Aug 2006 15:06 GMT
TimDouglas was telling us:
TimDouglas nous racontait que :

> Hi all,
>
> I have a macro which adds extra text into the table of contents, but
> for it to work correctly, the cursor needs to be placed at the end of
> the TOC.  Is there a way I can get word to place the cursor there
> automatically, rather than making the user do it?

   Dim rgePostTOC As Range

   Set rgePostTOC = ActiveDocument.TablesOfContents(1).Range

   With rgePostTOC
       .Collapse wdCollapseEnd
   End With

will place the range right after the TOC, then, if you are adding text, use
something like:

   Dim rgePostTOC As Range

   Set rgePostTOC = ActiveDocument.TablesOfContents(1).Range

   With rgePostTOC
       .Collapse wdCollapseEnd
       .InsertAfter "New text"
   End With

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.