INSERTING A DIRECTORY LISTING

M

MRC

I would like to insert a listing of the contents in a file
system into a Word Document. Is there a simple way to
accomplish this?
 
J

Jay Freedman

MRC said:
I would like to insert a listing of the contents in a file
system into a Word Document. Is there a simple way to
accomplish this?

See http://word.mvps.org/FAQs/MacrosVBA/ReadFilesIntoArray.htm for the
general idea. Since you don't need an array, you can simply dump the file
names directly into the document -- that is, replace the line

DirectoryListArray(Counter) = MyFile

with

Selection.InsertBefore MyFile & vbCr

You don't need the Counter variable unless you want to print the number of
files at the end of the listing; and you don't need the Dim
DirectoryListArray statement or the ReDim statement.
 
J

Jay Freedman

Jay Freedman said:
See http://word.mvps.org/FAQs/MacrosVBA/ReadFilesIntoArray.htm for the
general idea. Since you don't need an array, you can simply dump the file
names directly into the document -- that is, replace the line

DirectoryListArray(Counter) = MyFile

with

Selection.InsertBefore MyFile & vbCr

You don't need the Counter variable unless you want to print the number of
files at the end of the listing; and you don't need the Dim
DirectoryListArray statement or the ReDim statement.

Hmmm, try before you buy... it should be .InsertAfter rather than
..InsertBefore. My original version would get you a listing in
descending order.
 

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