Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default listing excel file in a folder

Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default listing excel file in a folder

Hi,

If all you want is the filename then right click your sheet tab, view code
and paste this in and run it. Change MyPath to your desired path

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
x = 1
MyPath = "C:\" 'Change this to your directory
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Cells(x, 1).Value = ActiveFile
x = x + 1
ActiveFile = Dir()
Application.DisplayAlerts = True
End Sub

Mike

"asrul" wrote:

Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default listing excel file in a folder


Something went wrong in pasting this, try this instead

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
x = 1
MyPath = "C:\" 'Change this to your directory
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Cells(x, 1).Value = ActiveFile
x = x + 1
ActiveFile = Dir()
Loop
Application.DisplayAlerts = True
End Sub

Mike
"Mike H" wrote:

Hi,

If all you want is the filename then right click your sheet tab, view code
and paste this in and run it. Change MyPath to your desired path

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
x = 1
MyPath = "C:\" 'Change this to your directory
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Cells(x, 1).Value = ActiveFile
x = x + 1
ActiveFile = Dir()
Application.DisplayAlerts = True
End Sub

Mike

"asrul" wrote:

Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default listing excel file in a folder

Hi asrul

Sub ListFiles()
Dim i As Integer
With Application.FileSearch
..NewSearch
..LookIn = "C:\MyFolder\MySubFolder" 'change as required
..SearchSubFolders = True
..Filename = "*.xls"
..Execute
For i = 1 To .FoundFiles.Count
ActiveSheet.Range("A65000").End(xlUp).Offset(1, 0) = .FoundFiles(i)
Next i
End With
End Sub


--

Regards

William




"asrul" wrote in message
...
Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default listing excel file in a folder


Change path to suit

Add other Excel file types as required by changing
Case "xls"
to
Case "xls", "xlm"





Sub ListExcelFiles()
Dim lRow As Long
Dim sPath As String
Dim sFname As String
Dim sTmpArr() As String

sPath = "c:\Temp\"

sFname = Dir(sPath, vbNormal)
lRow = 1
Do Until sFname = ""
sTmpArr = Split(sFname, ".")
Select Case LCase(sTmpArr(UBound(sTmpArr)))
Case "xls"
lRow = lRow + 1
Cells(lRow, "a").Value = sFname
End Select
sFname = Dir
Loop
End Sub


--
mudraker

If my reply has assisted or failed to assist you I welcome your
Feedback.

www.thecodecage.com
------------------------------------------------------------------------
mudraker's Profile: http://www.thecodecage.com/forumz/member.php?userid=18
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69125



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default listing excel file in a folder

You can use the following code:

Sub AAA()
Dim R As Range
Dim N As Long
Dim FName As String
Dim FolderName As String
Set R = Range("A1") '<<< Listing start cell
FolderName = "C:\SiteStats" '<<< Change to directory to list
FName = Dir(FolderName & "\*.xl*")
Do Until FName = vbNullString
R.Value = FName ' <<< File name only
' OR
R.Value = FolderName & "\" & FName
Set R = R(2, 1)
FName = Dir()
Loop
End Sub


Change the lines marked with <<< to the appropriate values. You may
also be interested in my Directory Tree Builder add-in that will do
this and much more. See http://www.cpearson.com/excel/FolderTree.aspx

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


On Fri, 27 Feb 2009 17:13:06 +0700, "asrul" wrote:

Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default listing excel file in a folder

Hi Mike,
Thank's,but I don't get the file name list in my worksheet.
Is there something I miss.
Another request,I also want to add the creation date of the
file in my list.
Thank you.

"Mike H" wrote in message
...

Something went wrong in pasting this, try this instead

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
x = 1
MyPath = "C:\" 'Change this to your directory
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Cells(x, 1).Value = ActiveFile
x = x + 1
ActiveFile = Dir()
Loop
Application.DisplayAlerts = True
End Sub

Mike
"Mike H" wrote:

Hi,

If all you want is the filename then right click your sheet tab, view

code
and paste this in and run it. Change MyPath to your desired path

Sub LoopThroughDirectory()
Application.DisplayAlerts = False
x = 1
MyPath = "C:\" 'Change this to your directory
ActiveFile = Dir(MyPath & "*.xls")
Do While ActiveFile < ""
Cells(x, 1).Value = ActiveFile
x = x + 1
ActiveFile = Dir()
Application.DisplayAlerts = True
End Sub

Mike

"asrul" wrote:

Hi All,

I want to listing all excel file in a directory.
And put in a worksheet.
How to code it.

Thank's in advance





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 listing Esradekan Excel Worksheet Functions 5 March 31st 10 12:33 AM
Listing Folder Contents into a Column LyndieBee Excel Worksheet Functions 1 August 29th 07 03:16 PM
Listing the contents of a folder [email protected] Excel Discussion (Misc queries) 2 April 12th 07 03:54 AM
Followup: Folder listing [email protected] Excel Discussion (Misc queries) 1 February 23rd 07 02:23 AM
Listing files within a folder Jeff Excel Programming 3 December 15th 03 12:28 PM


All times are GMT +1. The time now is 11:05 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"