Solved

Aligning content of TOC through programming

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
All doc, xls, and pdf's are gone 9 73
Using "ScreenUpdating" 6 45
MS Date Picker 64 bit 32 bit issue 12 42
Not needed 13 54
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now