Inserting folder names and files into a document 
Author Message
 Inserting folder names and files into a document

Hello all,

 I can pull all sub folders from a folder or I can pull all files from a
folder and insert them in my open document - but I cannot do both!

Is there a way to choose a starting point, list all sub -folders, and list
all the files in the sub folders?  I've wasted a lot of time trying to
figure this one out, any help would be appreciated.

Rob



Mon, 01 Aug 2005 13:19:33 GMT  
 Inserting folder names and files into a document
Hi Rob,

It's not exactly what you're asking for, but it might give you some ideas on
how to tackle your problem.
"How to get the names of all the folders in the folder tree, starting from a
specified folder" at
http://www.mvps.org/word/FAQs/MacrosVBA/ReadFoldersIntoArray.htm

In fact, once you have the name of a folder, you can get all the file names
into an array (" How to read the filenames of all the files in a directory
into an array" at
http://www.mvps.org/word/FAQs/MacrosVBA/ReadFilesIntoArray.htm or " Insert
into a document the names of all files in a selected folder" at
http://www.mvps.org/word/FAQs/MacrosVBA/InsertFileNames.htm

HTH


Quote:
> Hello all,

>  I can pull all sub folders from a folder or I can pull all files from a
> folder and insert them in my open document - but I cannot do both!

> Is there a way to choose a starting point, list all sub -folders, and list
> all the files in the sub folders?  I've wasted a lot of time trying to
> figure this one out, any help would be appreciated.

> Rob



Mon, 01 Aug 2005 21:50:03 GMT  
 Inserting folder names and files into a document
Hi Rob,

Here's example:

'Reference to MS Scripting Runtime needed
Dim f As New FileSystemObject
Dim MySubFolders    As Folders
Dim MyFiles         As Files

'get all subfolders in c:\temp
Set MySubFolders = _
    f.GetFolder("c:\temp").SubFolders

'get all files in c:\temp
Set MyFiles = _
    f.GetFolder("c:\temp").Files

'print each filename
Dim fFile   As File
For Each fFile In MyFiles
    Debug.Print fFile.Name
Next

'print each subfolder's name
Dim fFolder As Folder
For Each fFolder In MySubFolders
    Debug.Print fFolder.Name
Next

'go nothing
Set MySubFolders = Nothing
Set MyFiles = Nothing
Set f = Nothing

Krgrds,
Perry



Quote:
> Hello all,

>  I can pull all sub folders from a folder or I can pull all files from a
> folder and insert them in my open document - but I cannot do both!

> Is there a way to choose a starting point, list all sub -folders, and list
> all the files in the sub folders?  I've wasted a lot of time trying to
> figure this one out, any help would be appreciated.

> Rob



Tue, 02 Aug 2005 04:48:47 GMT  
 Inserting folder names and files into a document
Perry - It completely slipped my mind that I had components/objects
available to me.  My VB is a little rusty (I haven't used it since college),
but I'm determined to use VBA to get the most out of my office applications.
Thanks for the assistance.


Quote:
> Hi Rob,

> Here's example:

> 'Reference to MS Scripting Runtime needed
> Dim f As New FileSystemObject
> Dim MySubFolders    As Folders
> Dim MyFiles         As Files

> 'get all subfolders in c:\temp
> Set MySubFolders = _
>     f.GetFolder("c:\temp").SubFolders

> 'get all files in c:\temp
> Set MyFiles = _
>     f.GetFolder("c:\temp").Files

> 'print each filename
> Dim fFile   As File
> For Each fFile In MyFiles
>     Debug.Print fFile.Name
> Next

> 'print each subfolder's name
> Dim fFolder As Folder
> For Each fFolder In MySubFolders
>     Debug.Print fFolder.Name
> Next

> 'go nothing
> Set MySubFolders = Nothing
> Set MyFiles = Nothing
> Set f = Nothing

> Krgrds,
> Perry



> > Hello all,

> >  I can pull all sub folders from a folder or I can pull all files from a
> > folder and insert them in my open document - but I cannot do both!

> > Is there a way to choose a starting point, list all sub -folders, and
list
> > all the files in the sub folders?  I've wasted a lot of time trying to
> > figure this one out, any help would be appreciated.

> > Rob



Tue, 02 Aug 2005 13:35:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting embedded document file names from parent document

2. Naming the Spool File Document Name in VB5

3. Inserting names into Word Document from the web

4. Get one file name in a folder of many files and put in a string

5. Need Help with Inserting a file into a document

6. Inserting file location in a document

7. inserting external file into Word 2000 document???

8. Macro enabling us to insert multiple files into a single word document

9. Inserting multiple files into a single word document - Word97

10. Inserting DOC files into Word97 document

11. Insert a document into another document with a Form at startup

12. VBA code to print all icon-inserted documents within a document

 

 
Powered by phpBB® Forum Software