'This file is distributed "as is", e.g. there are no warranties 

'and obligations and you could use it in your applications on your

'own risk. Although your comments and questions are welcome.

'

'Author: (c) Dan Kozub, 1999

'URL   : http://members.tripod.com/~DanKozub

'Email : Dan_Kozub@usa.net, Dan_Kozub@pemail.net

'Last Modified: March 27,1999

'Version: 1.0

'Copy contents of this file to the existing macro file 

'OR add this file to list of macro files (Tools\Macro\Options>>\Loaded Files)

Dim AutoContents_GoFrom 

Dim AutoContents_GoTo 

sub CreateAutoContents()

set sel = ActiveDocument.Selection

insert_position = sel.CurrentLine

sel.StartOfDocument

ExecuteCommand "WBGoToNext"

first_line= sel.CurrentLine

count = 1

prev = -1

do 

ExecuteCommand "WBGoToNext"

cur_line= sel.CurrentLine

if cur_line <= first_line then exit do

count = count +1

loop

text = "/*   AutoContents generated "+Cstr(Date())+","+Cstr(Time())+vbCrLf

sel.StartOfDocument

for i=1 to count

ExecuteCommand "WBGoToNext"

cur_line= sel.CurrentLine

line_text = left(sel.Text,len(sel.Text)-1)

if (len(line_text)<80) then line_text = line_text+space(80-len(line_text))

text = text + line_text+" "+cstr(cur_line+count+2)+vbCrLf

next

text = text +"*/"+vbCrLf

sel.gotoline insert_position

sel.Text = text

end sub

sub AutoContentsGo()

set sel = ActiveDocument.Selection

sel.SelectLine

if Len(sel.Text)=2 then  CreateAutoContents : Exit Sub

sel.EndOfLine

sel.WordLeft  dsExtend

text = sel.Text

lline = sel.CurrentLine

if AutoContents_GoTo<>0 and lline >= AutoContents_GoTo then  

sel.StartOfDocument 

sel.GotoLine AutoContents_GoFrom

AutoContents_GoTo = 0

Exit sub

end if

AutoContents_GoFrom = lline

On Error Resume Next

lline = CLng(text)

if Err.Number <> 0 then 

sel.StartOfDocument 

else

sel.EndOfDocument 

sel.GotoLine lline

AutoContents_GoTo = lline

end if

end sub