×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

TOC in Word

TOC in Word

TOC in Word

(OP)
This question was announced mid october but noone replied, maybe because a wrong subject?

Cant anyone help me ??

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

cll

RE: TOC in Word

See if you can find one of the MS Word user groups. They are frequented by some very knowledgable folks.

As a rule, I wouldn't expect the ENG-TIPS techies to be up on the intracacies of Word.

RE: TOC in Word

Try posting this question at Tek-tips.com.  They're more into Office and Word problems

TTFN

RE: TOC in Word

(OP)
Thanks,
You might be right!
(- already tried EngTips).
Have found another promising link www.mvps.org/word.

Regards
cll

RE: TOC in Word

(OP)
Thanks to the hints, 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
cll

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources