Solved

Aligning content of TOC through programming

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
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…

734 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