Make an index page with hyperlinks to the index files

G

GUS

I want a macro to search at all documents in a dir and when finds the first
empty line then copy the above paragraph and paste it in a single document.
After that the macro must create a hyperlink from this paragraph to the file
which contain this paragraph.
I hope somebody understood wht i am trying to do.

Every document in this dir starts with a single paragraph (two or three
lines .The paragraph it's a sort description for the rest of the document)

I want to make a file with all the first paragraphs (short descriptions)
in which every paragraph will link to the apropriate file.

It's vey easy to do that manually but the files in the dir is 1600 and i
want a macro to do that fast.
 
C

Caroline Miller

Try the following (changing folder name)


Option Explicit
Option Compare Text

Sub createindex()
Dim fso As Scripting.FileSystemObject
Dim afile As Scripting.file
Dim fld As Scripting.Folder
Dim fullname As String
Dim Paratext As String
Dim myword As Word.Application

Set myword = New Word.Application
Set fso = New Scripting.FileSystemObject
'Change path to folder to be searched
Set fld = fso.GetFolder("c:\test")

On Error Resume Next
Word.Documents.Add

For Each afile In fld.Files
Paratext = ""
fullname = afile.Path
If Right(fullname, 4) = ".doc" Then
myword.Documents.Open FileName:=fullname,
ReadOnly:=True
Paratext = myword.ActiveDocument.Paragraphs
(1).Range.Text
myword.ActiveDocument.Close
savechanges:=wdDoNotSaveChanges
ActiveDocument.Hyperlinks.Add
Anchor:=Word.Selection.Range, _
Address:=fullname, TextToDisplay:=Paratext
Selection.TypeText vbCrLf
End If
Next afile
myword.Quit
End Sub
 
C

Caroline Miller

Forgot to say you need to add a reference to

Microsoft Scripting Runtime
 

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