Solved

Aligning content of TOC through programming

Posted on 2012-12-23
3
431 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
3 Comments
 
LVL 50

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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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 …

829 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