Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default How to scan directory , list all the file

Hi
How to scan directory, list all the file under particluar directory. I
want send those files by mail. Eeach time just send a file each time.

e.g. under c:\application\statement have a lot of *.xls. How to list
out all the file ?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default How to scan directory , list all the file

This code from Bob Phillips for listing file names and adding them to a
list box is a cool way of doing it, traditionally I thought this was
done using the dir method, but the below looks better:

Sub CreateFormsListBox()
Dim FSO As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object
Dim sPath As String
Dim oList As ListBox


Application.CommandBars("Forms").Visible = True
ActiveSheet.ListBoxes.Add(18, 12.75, 150, 200).Select
Selection.OnAction = "myPrintMacro"
Set oList = Selection


Set FSO = CreateObject("Scripting.FileSystemObject")


sPath = "C:\MyTest"
Set Folder = FSO.GetFolder(sPath)


Set Files = Folder.Files
For Each file In Files
oList.AddItem file.Name
Next file


Range("A1").Select


End Sub


I'm sure you can easily adapt the above.
Rgds
J


On Oct 23, 12:15 pm, "moonhk" wrote:
Hi
How to scan directory, list all the file under particluar directory. I
want send those files by mail. Eeach time just send a file each time.

e.g. under c:\application\statement have a lot of *.xls. How to list
out all the file ?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default How to scan directory , list all the file

Here is one you can adapt using DIR

Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub

--
Don Guillett
SalesAid Software

"moonhk" wrote in message
ps.com...
Hi
How to scan directory, list all the file under particluar directory. I
want send those files by mail. Eeach time just send a file each time.

e.g. under c:\application\statement have a lot of *.xls. How to list
out all the file ?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default How to scan directory , list all the file

Thank Both
Just test below coding , it works.
Option Explicit

Sub anotherfindfiles()
'2006/10/23
'http://groups.google.com/group/microsoft.public.excel.programming/
'
browse_frm/thread/29c831da7ff12191/c93692d9863e97fd#c93692d9863e97fd
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim Msg As String

Dim ThisRow As Long
Dim MediaFileLocation As String
Msg = ""
'MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
MediaFileLocation = "D:\Example\EXCEL\*.xls"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
'Cells(ThisRow, 1) = FN
Msg = Msg + FN + Chr(13)
FN = Dir
Loop
Application.ScreenUpdating = True
MsgBox Msg
End Sub



Don Guillett wrote:
Here is one you can adapt using DIR

Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub

--
Don Guillett
SalesAid Software

"moonhk" wrote in message
ps.com...
Hi
How to scan directory, list all the file under particluar directory. I
want send those files by mail. Eeach time just send a file each time.

e.g. under c:\application\statement have a lot of *.xls. How to list
out all the file ?


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 open a file without having it run virus scan Mickey Excel Discussion (Misc queries) 2 September 24th 09 03:38 PM
Scan directory and import file conditionaly Michael.Tarnowski Excel Worksheet Functions 3 March 30th 09 02:00 PM
Scan column for first of a list Chip Excel Discussion (Misc queries) 1 May 24th 08 05:19 PM
Scan a Directory jjresti Excel Programming 5 September 9th 05 12:08 PM
macro to scan list Matto Excel Programming 2 November 9th 04 05:19 PM


All times are GMT +1. The time now is 04:30 AM.

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"