![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Newb needing VBA solution to change formatting
|
derekcentrico | Word VBA | 10 | 12-12-2016 12:27 PM |
newb - search and replace - WILDCARDS - keep original...?
|
Bansaw | Word | 4 | 09-01-2016 11:16 AM |
| Backing up importing & exporting ?? I am a newb | Jazz | OneNote | 0 | 01-27-2016 10:18 PM |
newb - need help automating catalogue production
|
Deeper | Office | 2 | 09-09-2015 01:45 AM |
| NEWB to Macros - formatting exports | EC37 | Excel Programming | 52 | 06-25-2014 06:26 AM |