create a document containing a list of all documents in a folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to create a document that contains a listing of the contents of a folder. I have done this before but now can't find the document I saved the Macro in. I have found a posting (http://word.mvps.org/faqs/general/PrintDocList.htm) that tells me how to print this (and I can't make it work!) but I can't find one that tells me how to create a document listing the contents (like an index to the folder)

Any help you can provide will be appreciated
 
Christine said:
I need to create a document that contains a listing of the contents of a folder. I have done this before but now can't find the document I saved the Macro in. I have found a posting (http://word.mvps.org/faqs/general/PrintDocList.htm) that tells me how to print this (and I can't make it work!) but I can't find one that tells me how to create a document listing the contents (like an index to the folder).

Any help you can provide will be appreciated.
Hi, Christine,

Try this one. Using the Copy dialog to acquire the folder name is a
bit clunky, but telling you how to do anything better would take a
while unless you had some programming background.

Public Sub FolderListing()
Dim ListDoc As Document
Dim FolderName As String, FileName As String

With Dialogs(wdDialogCopyFile)
If .Display = -1 Then
FolderName = .directory
Else
Exit Sub
End If
End With

FolderName = Replace(FolderName, Chr(34), "")

Set ListDoc = Documents.Add
ListDoc.Range.Text = "Contents of " & FolderName & vbCr & vbCr

FileName = Dir(FolderName & "*.*")
Do While FileName <> ""
ListDoc.Range.InsertAfter FileName & vbCr
FileName = Dir()
Loop

Set ListDoc = Nothing
End Sub
 
Back
Top