• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

word insert a table of context

hi.
i cant insert a table of index in my word document
the macro that i have recorde is the foloowing:


 With ActiveDocument
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
            True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
            LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
            UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
            True
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
        .TablesOfContents.Format = wdIndexIndent
    End With

in my vb application i added:
doc.TablesOfContents.Add(doc.Range.Bookmarks.Item("\endofdoc").Range, RightAlignPageNumbers:=True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
            LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
            UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
            True)
                            'doc.TablesOfContents(1).TabLeader = Word.WdTabLeader.wdTabLeaderDots
' didnt find wdIndexIndent in the word DLL
' and i didnt see the table of index on my word document
any idea why?? by the way i have set some parts of the document as heading 1
0
mte01
Asked:
mte01
  • 4
  • 2
1 Solution
 
omegaomegaDeveloperCommented:
Hello, mte01,

No.  I don't know why some constants are missing.  You can look up the values of the missing constants in the Word VBA object browser and then define corresponding constants in your .Net application.

Your "doc.TablesOfContents.Add" statement worked fine for me once I dropped "UseOutlineLevels:=True".  My IDE (VB .Net 2003) flags this as a syntax error.

Cheers,
Randy
0
 
mte01Author Commented:
>>omegaomega

Thanks for your reply..can you clarify more your comment?...I didn't understand it quite well.....
0
 
omegaomegaDeveloperCommented:
Hello, mte01,

The following code sample (extracted from a Form with a single button) works correctly for me:

    Dim mappWord As New Word.Application

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        mappWord.Visible = True
        Dim docTest As Word.Document = mappWord.Documents.Open("J:\Test\Word Table\Test.doc")

        docTest.TablesOfContents.Add(docTest.Range.Bookmarks.Item("\endofdoc").Range, _
            RightAlignPageNumbers:=True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
            LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
            UseHyperlinks:=True, HidePageNumbersInWeb:=True)

    End Sub

Cheers,
Randy
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
mte01Author Commented:
thanks Randy...
0
 
mte01Author Commented:
>>omegaomega

Can you please help in the following question: http:Q_21850350.html
0
 
mte01Author Commented:
>>omegaomega

Can you please help in the following question:   http:Q_21861767.html
0

Featured Post

Independent Software Vendors: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now