Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Display Contents of Folder

I'm in need of VBA code that will list in an Excel sheet the filenames of all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Display Contents of Folder

This will do that, it stores them in an array then writes it to sheet1

Function GetFileNames()

Dim MyName, MyPath
Dim FNames()

'Find how many file exist

ReDim FNames(0)

MyPath = "C:\" 'You need to change this to your requirement
MyName = Dir(MyPath, vbDirectory)
Do While MyName < ""

If MyName < "." And MyName < ".." Then

On Error Resume Next
If (GetAttr(MyPath & MyName) And vbDirectory) < vbDirectory Then
ReDim Preserve FNames(UBound(FNames) + 1)
FNames(UBound(FNames)) = MyPath & MyName
End If

End If

MyName = Dir

Loop

For x = 1 To UBound(FNames)
Sheet1.Cells(x, 1) = FNames(x)
Next x

End Function

--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Display Contents of Folder

This will put a list of files in column G. Change MYPATH to the path for
the folder you want to look at, ending with a backslash \ Hope this
helps, James

Const MYPATH = "c:\MyFiles\"

Sub ListFiles()
Dim PutRow As Long, fName As String
PutRow = 1
Columns("g").Clear
fName = Dir(MYPATH & "*.*")
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Do
fName = Dir
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Loop Until fName = ""
End Sub

"Chad" wrote in message
...
I'm in need of VBA code that will list in an Excel sheet the filenames of
all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Display Contents of Folder

I use this routine

Sub Searchfolder()

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\User\My Documents" 'Your path here
.Filename = "*"
.Searchsubfolders = False
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."

For I = 1 To .FoundFiles.Count
'Truncate to File Name
flstring = .FoundFiles(I)
namelen = InStrRev(flstring, "\")
flstring = Right(flstring, Len(flstring) - namelen)
'Output to sheet
ActiveCell = flstring
ActiveCell.Offset(1, 0).Select
Next I
Else
MsgBox "There were no files found."
End If
End With

End Sub

"Chad" wrote:

I'm in need of VBA code that will list in an Excel sheet the filenames of all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Display Contents of Folder

I think this will work perfectly. Thank you so much!

-Chad


"Crowbar via OfficeKB.com" wrote:

This will do that, it stores them in an array then writes it to sheet1

Function GetFileNames()

Dim MyName, MyPath
Dim FNames()

'Find how many file exist

ReDim FNames(0)

MyPath = "C:\" 'You need to change this to your requirement
MyName = Dir(MyPath, vbDirectory)
Do While MyName < ""

If MyName < "." And MyName < ".." Then

On Error Resume Next
If (GetAttr(MyPath & MyName) And vbDirectory) < vbDirectory Then
ReDim Preserve FNames(UBound(FNames) + 1)
FNames(UBound(FNames)) = MyPath & MyName
End If

End If

MyName = Dir

Loop

For x = 1 To UBound(FNames)
Sheet1.Cells(x, 1) = FNames(x)
Next x

End Function

--
Message posted via http://www.officekb.com




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Display Contents of Folder

You can use my DirTree add-in that will list the subfolders and files of a
specified folder, with many display options. See
www.cpearson.com/Excel/FolderTree.aspx


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

"Chad" wrote in message
...
I'm in need of VBA code that will list in an Excel sheet the filenames of
all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Display Contents of Folder

Is it possible to access the indvidual file attributes that I can view
in different columns within Windows 'Exploder' (ie: Attributes, Owner,
Author, Title, Artist, etc)? And if so, are there any VBA examples
out there I could look at? Thanks. -pb

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Display Contents of Folder

I suggest downloading Tushar's Directory Listing add-in from

http://www.tushar-mehta.com/ scroll down to Add-insDirectory
Listing.

Download the ZIP file and un-zip to your Office\Library folder.


Gord Dibben MS Excel MVP

On Tue, 16 Oct 2007 13:59:46 -0700, cubbybear3 wrote:

Is it possible to access the indvidual file attributes that I can view
in different columns within Windows 'Exploder' (ie: Attributes, Owner,
Author, Title, Artist, etc)? And if so, are there any VBA examples
out there I could look at? Thanks. -pb


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Display Contents of Folder

Is it possible to get a list of the entire folder contents, including other
folders that may exist? This code works perfectly to list all files outside
of folders within the desired destination.

Thanks!


"Zone" wrote:

This will put a list of files in column G. Change MYPATH to the path for
the folder you want to look at, ending with a backslash \ Hope this
helps, James

Const MYPATH = "c:\MyFiles\"

Sub ListFiles()
Dim PutRow As Long, fName As String
PutRow = 1
Columns("g").Clear
fName = Dir(MYPATH & "*.*")
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Do
fName = Dir
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Loop Until fName = ""
End Sub

"Chad" wrote in message
...
I'm in need of VBA code that will list in an Excel sheet the filenames of
all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Display Contents of Folder

Change it like this to get files plus subdirectories.

fName = Dir(MYPATH, vbDirectory)

This doesn't show the files within the subdirectories, but you can do add
the subdirectories to the path one at a time, then do Dir to get those
files. HTH, James

"Chad" wrote in message
...
Is it possible to get a list of the entire folder contents, including
other
folders that may exist? This code works perfectly to list all files
outside
of folders within the desired destination.

Thanks!


"Zone" wrote:

This will put a list of files in column G. Change MYPATH to the path for
the folder you want to look at, ending with a backslash \ Hope this
helps, James

Const MYPATH = "c:\MyFiles\"

Sub ListFiles()
Dim PutRow As Long, fName As String
PutRow = 1
Columns("g").Clear
fName = Dir(MYPATH & "*.*")
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Do
fName = Dir
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Loop Until fName = ""
End Sub

"Chad" wrote in message
...
I'm in need of VBA code that will list in an Excel sheet the filenames
of
all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad






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
Folder Contents to Excel TC Daniel Excel Discussion (Misc queries) 2 January 23rd 08 05:53 PM
Listing the contents of a folder [email protected] Excel Discussion (Misc queries) 2 April 12th 07 03:54 AM
To display contents of a folder in an excel sheet using Excel MACRO [email protected] Excel Worksheet Functions 1 June 24th 06 01:18 AM
Add contents of A1 in all workbooks within a folder Steph[_3_] Excel Programming 18 October 4th 04 11:52 PM
contents of folder Mark[_17_] Excel Programming 2 September 10th 04 03:03 PM


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

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"