PC Review


Reply
Thread Tools Rate Thread

Create list of folders

 
 
kaiser
Guest
Posts: n/a
 
      19th Jul 2007
Hi all

I am trying to create a list of folders but not sub folders in excel.

For example, If i have a folder with the path c:\test\

and in test there are three folders ("Folder1, Folder2, Folder3") and
Folder1 has a folder in in called "Folder1.1" i want the output to be

c:\test\folder
c:\test\folder1
c:\test\folder2
c:\test\folder3

I have the following code from this forum. HOw do i ammend it to not
include sub folders?

Set a reference (in VBA, Tools menu, References item) to
Microsoft Scripting Library and use code like the following:


Sub Start()
Dim FSO As Scripting.FileSystemObject
Dim TopFolder As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set TopFolder = FSO.GetFolder("C:\Temp")
DoOneFolder TopFolder
End Sub


Sub DoOneFolder(F As Scripting.Folder)
Dim OneFolder As Scripting.Folder
'
' do something with F
Debug.Print F.Path


For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder
End Sub

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      20th Jul 2007
That look like some of my code. If you just want the immediate subfolders
of a given folder without listing the nest subfolders, use code like the
following:

Sub AAA()
Dim FSO As Scripting.FileSystemObject
Dim Rng As Range
Dim FolderName As String
Dim SubF As Scripting.Folder

FolderName = InputBox("Enter a folder name.")
If FolderName = vbNullString Then
Exit Sub
End If
If Dir(FolderName, vbDirectory) = vbNullString Then
MsgBox "Folder not found."
Exit Sub
End If
Set Rng = Range("A1")
Set FSO = New Scripting.FileSystemObject

For Each SubF In FSO.GetFolder(FolderName).SubFolders
Rng.Value = SubF.Path
Set Rng = Rng(2, 1)
Next SubF
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"kaiser" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all
>
> I am trying to create a list of folders but not sub folders in excel.
>
> For example, If i have a folder with the path c:\test\
>
> and in test there are three folders ("Folder1, Folder2, Folder3") and
> Folder1 has a folder in in called "Folder1.1" i want the output to be
>
> c:\test\folder
> c:\test\folder1
> c:\test\folder2
> c:\test\folder3
>
> I have the following code from this forum. HOw do i ammend it to not
> include sub folders?
>
> Set a reference (in VBA, Tools menu, References item) to
> Microsoft Scripting Library and use code like the following:
>
>
> Sub Start()
> Dim FSO As Scripting.FileSystemObject
> Dim TopFolder As Scripting.Folder
> Set FSO = New Scripting.FileSystemObject
> Set TopFolder = FSO.GetFolder("C:\Temp")
> DoOneFolder TopFolder
> End Sub
>
>
> Sub DoOneFolder(F As Scripting.Folder)
> Dim OneFolder As Scripting.Folder
> '
> ' do something with F
> Debug.Print F.Path
>
>
> For Each OneFolder In F.SubFolders
> DoOneFolder OneFolder
> Next OneFolder
> End Sub
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create folders from list vb/macro? Sherri Microsoft Excel Misc 0 13th May 2009 07:30 PM
How to create folders in outlook from folders list in excel =?Utf-8?B?TWlrZQ==?= Microsoft Outlook Discussion 1 19th Jan 2006 11:11 PM
Create Distribution List from Contact List in Public Folders. =?Utf-8?B?REpS?= Microsoft Outlook Contacts 4 14th Jul 2005 04:56 PM
Create folders from list in column saybut Microsoft Excel Misc 2 2nd Apr 2004 10:15 AM
create list of files & folders =?Utf-8?B?bmhhcnJpcw==?= Microsoft Excel Worksheet Functions 2 5th Feb 2004 09:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:26 AM.