Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Aligning content of TOC through programming

Posted on 2012-12-23
3
Medium Priority
?
453 Views
Last Modified: 2012-12-26
Hello,
             I want to know the code required to align the content (headings) of a TOC in word document through Visual Basic 6.0. I have attached two screen shots for your reference. First picture (CurrentScenario.jpg) shows the current scenario and the other picture (ExpectedScenario.jpg) show the expected scenario.

Also I have given below the existing Visual Basic 6.0 code that provides the existing alignment (current scenario) of the TOC in word document.

strAddedStyles = "Heading 1,1"

WdDoc.TablesOfContents.add(Range:=WdDoc.bookmarks.Item("\endofdoc").Range, _
                                                          UseHeadingStyles:=True, UpperHeadingLevel:=1, _
                       LowerHeadingLevel:=3, AddedStyles:=strAddedStyles, UseHyperlinks:=True)

Open in new window

CurrentScenario.jpg
ExpectedScenario.jpg
0
Comment
Question by:Gopinath74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 38717973
Hi,

Could you send a sample of you doc?

or have you checked whether all the references were in order

TOC
Regards
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 38718127
Try this.
Dim toc As Word.TableOfContents
Dim para As Word.Paragraph
Dim rng As Word.Range
For Each toc In WdDoc.TablesOfContents
    Set rng = toc.Range
    rng.MoveEnd wdCharacter, -1
    For Each para In rng.Paragraphs
        Select Case para.Style
            Case "TOC 2", "TOC 3"
            para.LeftIndent = CentimetersToPoints(2)
        End Select
    Next para
Next toc

Open in new window

The VB6 code and the VBA code are virtually identical.
0
 

Author Closing Comment

by:Gopinath74
ID: 38722635
The solution worked as expected. Thanks a lot GrahamSkan.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question