Consulting

Results 1 to 4 of 4

Thread: If Table of Contents Exists Then?

  1. #1
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location

    Question If Table of Contents Exists Then?

    Hi all,

    Is there anyway that I could macro if a table of contents exists then do x?

    The example is that a document can contain Clauses and Schedules which are both table of contents in their own right. One will always exist where as the other may not. I have a macro which deletes both of them but if one doesn't exist it errors.

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Have you tried simply handling the error.

    On Error Resume Next
    IDontExist.Delete 'Will raise error since that which does not exist cannot be deleted.
    On Error GoTo 0
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You could use:
    Dim TOC As TableOfContents
    For Each TOC In ActiveDocument.TablesOfContents
      TOC.Delete
    Next
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location
    Thanks both,

    I've used your solution macropod. Legend!

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •