Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA help: need folder names

what i'm looking for is a simple vba code to pull all the folder names
from somewhere on a disk (like C:\). i do not want subfolders listed.
i also want it to list the folder names exactly how it is in the
folder (i have them listed by date modified from oldest to newest).
i'm using excel 2003. thanks for your time.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA help: need folder names

Try code like the following. You'll need a reference to the Microsoft
Scripting RunTime (in VBA, Tools menu, References item, in that dialog
choose Microsoft Scripting RunTime).

Sub ListFolders()
Dim FSO As Scripting.FileSystemObject
Dim FF As Scripting.Folder
Dim R As Range

Set R = Range("A1") '<<<< CHANGE OUTPUT START CELL
Set FSO = New Scripting.FileSystemObject
For Each FF In FSO.GetFolder("C:\").SubFolders '<<< CHANGE DRIVE SPEC
R(1, 1).Value = FF.Name
R(1, 2).Value = FF.DateLastModified
Set R = R(2, 1)
Next FF
Set R = Range(Range("A1"), R).Resize(, 2)
R.Sort key1:=R(1, 2), order1:=xlAscending, header:=xlNo,
MatchCase:=False
R.Columns(2).Clear
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


wrote in message
...
what i'm looking for is a simple vba code to pull all the folder names
from somewhere on a disk (like C:\). i do not want subfolders listed.
i also want it to list the folder names exactly how it is in the
folder (i have them listed by date modified from oldest to newest).
i'm using excel 2003. thanks for your time.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA help: need folder names

thanks for your reply Chip. unfortunately, there's a syntax error; the
following is in red:

R.Sort key1:=R(1, 2), order1:=xlAscending, header:=xlNo,
MatchCase:=False

do you know how to fix it?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default VBA help: need folder names

That is all one line. Add a line-continuation character.

Don't forget the <space before the _

R.Sort key1:=R(1, 2), order1:=xlAscending, header:=xlNo, _
MatchCase:=False


Gord Dibben MS Excel MVP

On Sat, 16 Feb 2008 11:51:05 -0800 (PST), wrote:

thanks for your reply Chip. unfortunately, there's a syntax error; the
following is in red:

R.Sort key1:=R(1, 2), order1:=xlAscending, header:=xlNo,
MatchCase:=False

do you know how to fix it?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA help: need folder names

it works perfectly, many thanks!! =D


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VBA help: need folder names

it works perfectly, many thanks!! =D
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I paste a set of folder NAMES into a set of cells? Jedi Leba Excel Discussion (Misc queries) 2 September 13th 07 08:54 AM
How to List the names of the subfolders present in the folder (path of folder is given in the textbox by user ) divya Excel Programming 3 November 30th 06 11:34 AM
Extract folder names only Michael Singmin Excel Programming 4 February 12th 06 12:53 PM
How to Get Folder Names GC. Excel Programming 19 November 19th 04 12:10 PM
Change names of files in a folder to match names in Excel Column saybut Excel Programming 4 February 9th 04 06:26 PM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"