macro??? newbie

I

Isabel

Hello everyone
I have a bunch of word files and I would like to create a
toc of them, with date modified
I'm realy new at it, so I would appreciate some help

thks

Isabel
 
M

Mark Tangard

Hi Isabel,

Try the macro below.

To install it, see:
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Sub ListFilesWithDateModified
Dim folderpath As String, i As Long
askfolder:
folderpath = InputBox("Enter the path of the folder containing the files.")
If Trim(folderpath) = "" Then Exit Sub
If Dir$(folderpath, vbDirectory) = "" Then
MsgBox "Not a valid folder: " & folderpath & ". Try again."
GoTo askfolder
End If
Documents.Add
With ActiveDocument.Range
.Text = "Documents in " & folderpath & vbCr & vbCr
With .ParagraphFormat.TabStops
.ClearAll
.Add Position:=InchesToPoints(4.5), Leader:=wdTabLeaderDots
End With
End With
With Application.FileSearch
.NewSearch
.LookIn = folderpath
.SearchSubFolders = False
.FileName = "*.DOC"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
ActiveDocument.Range.InsertAfter _
Mid$(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") _
+ 1, 99) & vbTab & _
FileDateTime(.FoundFiles(i)) & vbCr
Next i
ActiveDocument.Paragraphs(1).Range.Bold = True
Else
MsgBox "No matching files found."
ActiveDocument.Close 0
End If
End With
End Sub
 

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