Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tabulated text in TOC Table of contents in WORD

Status
Not open for further replies.

cllpmc

Technical User
Sep 16, 2002
21
DK
Hi all
I have a weird problem with TOC
The following (simplified) code put a TC field and make a TOC from that:

Private Sub TabCon()

Selection.HomeKey unit:=wdStory

ActiveDocument.TablesOfContents.MarkEntry Range:=Selection.Range, _
Entry:="text1" & Chr(9) & "text2" & Chr(9) & "text3", TableID:="P"

Selection.EndKey unit:=wdStory

ActiveDocument.TablesOfContents.Add Range:=Selection.Range, UseFields:=True, _
UseHeadingStyles:=False, TableID:="P"

End Sub

While the TC field is inserted with tabulations:

{ TC "text1(tab)text2(tab)text3" \f P \l "1" }

where (tab) is the tabulation mark, the TOC is inserted only with the first tabulation (and tabulation for page) the second tabulation become a space:

text1(tab)text2 text3(tab)1
Field: { TOC \f P }

Can anyone explain it to me and/or solve the problem I would greately appreciate that - thanks!

Best regards

cllpmc


 
I have figured this solution out:

Private Sub tabcon1()

Selection.HomeKey Unit:=wdStory

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldTOCEntry, Text:= _
Chr(34) & "text1" & Chr(9) & "text2" & Chr(9) & "text3" & Chr(9) & "text4" & _
Chr(34) & "\f P \w", PreserveFormatting:=True

Dim Indholdrange As Range
Set Indholdrange = ActiveDocument.Bookmarks("PIndhold").Range

Selection.Fields.Add Range:=Indholdrange, Type:=wdFieldTOC, Text:= _
"\f P \w", preserveformatting:=True

End Sub

Take care of wordwrap. Bookmark is just to control where to insert the TOC.

If anyone should be interested.

Best regards
cllpmc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top