PDA

View Full Version : [SOLVED:] If Table of Contents Exists Then?



Bez
05-09-2014, 01:10 AM
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

gmaxey
05-09-2014, 01:50 PM
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

macropod
05-09-2014, 03:59 PM
You could use:

Dim TOC As TableOfContents
For Each TOC In ActiveDocument.TablesOfContents
TOC.Delete
Next

Bez
05-12-2014, 12:13 AM
Thanks both,

I've used your solution macropod. Legend!

Thanks