Solved

Aligning content of TOC through programming

Posted on 2012-12-23
3
436 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 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

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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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