Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default List ALL folders and files

Good afternoon,

I want to be able to list ALL the folders and ALL the files within
those folders.
I found this code which works brilliantly if there are just files on
the directory you specify.
Unfortunately it does not give me the folder names and then the files
within those folders.
Is there any way of adapting the code so it will do this please.
So basically it will list the first folder perhaps in non hyperlinked
black text and then the files within that folder in hyperlinked blue
text, then the second folder etc.

Sub HyperlinksToDirectory()
' Puts hyperlinks to each of the files in a directory of your
choice
' into the active sheet starting at the active cell
Dim stDir As String
Dim stFile As String
Dim R As Range
Set R = ActiveCell
stDir = InputBox("Directory?", , Default:=CurDir())
stFile = Dir(stDir & "\*.*")
Do Until stFile = ""
R.Hyperlinks.Add R, stDir & "\" & stFile, , , stFile
Set R = R.Offset(1)
stFile = Dir()
Loop
R.CurrentRegion.Sort key1:=R, order1:=xlAscending, header:=xlNo
End Sub

Thanks in advance,
PAB

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default List ALL folders and files

Take a look at Chip Pearson's add-in for listing subdirectories and files:

http://www.cpearson.com/excel/FolderTree.aspx





"Paul Black" wrote in message
...
Good afternoon,

I want to be able to list ALL the folders and ALL the files within
those folders.
I found this code which works brilliantly if there are just files on
the directory you specify.
Unfortunately it does not give me the folder names and then the files
within those folders.
Is there any way of adapting the code so it will do this please.
So basically it will list the first folder perhaps in non hyperlinked
black text and then the files within that folder in hyperlinked blue
text, then the second folder etc.

Sub HyperlinksToDirectory()
' Puts hyperlinks to each of the files in a directory of your
choice
' into the active sheet starting at the active cell
Dim stDir As String
Dim stFile As String
Dim R As Range
Set R = ActiveCell
stDir = InputBox("Directory?", , Default:=CurDir())
stFile = Dir(stDir & "\*.*")
Do Until stFile = ""
R.Hyperlinks.Add R, stDir & "\" & stFile, , , stFile
Set R = R.Offset(1)
stFile = Dir()
Loop
R.CurrentRegion.Sort key1:=R, order1:=xlAscending, header:=xlNo
End Sub

Thanks in advance,
PAB



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default List ALL folders and files

Maybe if you explain to Chip Pearson in your related thread why you couldn't
get his code to work he might suggest a simple solution (the hyperlinks
could easily be added in).

Regards,
Peter T



"Paul Black" wrote in message
...
Good afternoon,

I want to be able to list ALL the folders and ALL the files within
those folders.
I found this code which works brilliantly if there are just files on
the directory you specify.
Unfortunately it does not give me the folder names and then the files
within those folders.
Is there any way of adapting the code so it will do this please.
So basically it will list the first folder perhaps in non hyperlinked
black text and then the files within that folder in hyperlinked blue
text, then the second folder etc.

Sub HyperlinksToDirectory()
' Puts hyperlinks to each of the files in a directory of your
choice
' into the active sheet starting at the active cell
Dim stDir As String
Dim stFile As String
Dim R As Range
Set R = ActiveCell
stDir = InputBox("Directory?", , Default:=CurDir())
stFile = Dir(stDir & "\*.*")
Do Until stFile = ""
R.Hyperlinks.Add R, stDir & "\" & stFile, , , stFile
Set R = R.Offset(1)
stFile = Dir()
Loop
R.CurrentRegion.Sort key1:=R, order1:=xlAscending, header:=xlNo
End Sub

Thanks in advance,
PAB



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
List all folders and files Paul Black Excel Programming 2 February 24th 10 10:31 AM
macro to list folders only, not files jat Excel Worksheet Functions 4 April 3rd 09 06:36 PM
Using VBScript to list all folders in a directory and files ... scriptman Excel Programming 1 July 23rd 07 02:49 PM
Map/List of folders, subfolders & files Bogdan Excel Programming 5 June 11th 06 06:01 PM
Dir() function to return either List of files or folders R Avery Excel Programming 12 July 19th 04 09:29 PM


All times are GMT +1. The time now is 03:30 PM.

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

About Us

"It's about Microsoft Excel"