View Single Post
 
Old 06-28-2017, 04:23 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should work

Code:
Sub Macro2()
    With ActiveDocument
        'insert the TOC
        .TablesOfContents.Add _
                Range:=Selection.Range, _
                RightAlignPageNumbers:=True, _
                UseHeadingStyles:=True, _
                UpperHeadingLevel:=1, _
                LowerHeadingLevel:=5, _
                IncludePageNumbers:=True, _
                AddedStyles:="", _
                UseHyperlinks:=True, _
                HidePageNumbersInWeb:=True, _
                UseOutlineLevels:=True
        'select the TOC
        .TablesOfContents.Item(1).Range.Select
        'Unlink the TOC field
        Selection.Fields.Unlink
        'Copy the unlinked TOC
        Selection.Copy
        'Undo the unlinking to restore the TOC field
        ActiveDocument.Undo 1
        'Next line is optional
        '.TablesOfContents.Item(1).Range.Delete
    End With
    MsgBox "TOC Copied to clipboard"
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote