index

L

Laura

Hello and thanks in advanced:
I’m trying to build a TOC manually
I have to take all the phrases that are selected in the document, an put it
in a table of contents
The pseudo-code should be something like this:

Do
Look for underlined text
Place a mark Entry (at the beginning of the line)
loop Until end of document

Write the index at the beginning of the document

Well, my problem is that i don't know what it's wrong in my code, or waht i
have to do. the program, at the end of the document, begins another at the
beginning
thanks

Sub Macro()
'
'
Dim indice As String
Windows("combina.doc").Activate
Selection.WholeStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Do
Selection.Find.ClearFormatting
With Selection.Find
.Font.Underline = True
.Text = ""
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
indice = Selection.Text
ActiveWindow.ActivePane.View.ShowAll = True
Selection.HomeKey Unit:=wdLine ‘ its necessary because if you
don’t put the markEntry at the beginning of the line, it becomes an infinite
secuence
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range,
Entry:=indice

Loop Until ?????

‘ write the index at the beginning of the document
Selection.WholeStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
With ActiveDocument
.Indexes.Add Range:=Selection.Range, HeadingSeparator:= _
wdHeadingSeparatorNone, Type:=wdIndexIndent,
RightAlignPageNumbers:= _
True, NumberOfColumns:=1, IndexLanguage:=wdSpanishModernSort
.Indexes(1).TabLeader = wdTabLeaderDots
End With

End Sub
 
E

Ed

Why can't you use Word's TOC field? If you create a style and set your text
in that style, then tell the TOC field to use that style, you can build the
index and adjust it as your document changes.

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top