Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Directory List of Excel Files

Is there a way, through VB, to get a list of excel files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do want I
need anyway!

Any help would be great!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Directory List of Excel Files

Try to understand this example
http://www.rondebruin.nl/copy3.htm

Post back if you need help

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ...
Is there a way, through VB, to get a list of excel files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do want I
need anyway!

Any help would be great!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Directory List of Excel Files

What you have is great! But I will only need the list of
worksheets from each workbook. Can you provide some
assistance on that ???

-----Original Message-----
Try to understand this example
http://www.rondebruin.nl/copy3.htm

Post back if you need help

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message

...
Is there a way, through VB, to get a list of excel

files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do

want I
need anyway!

Any help would be great!!!



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Directory List of Excel Files

Try this

Sub test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles(i))
Cells(i, 3).Value = FileLen(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ...
What you have is great! But I will only need the list of
worksheets from each workbook. Can you provide some
assistance on that ???

-----Original Message-----
Try to understand this example
http://www.rondebruin.nl/copy3.htm

Post back if you need help

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message

...
Is there a way, through VB, to get a list of excel

files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do

want I
need anyway!

Any help would be great!!!



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Directory List of Excel Files

wrote:
What you have is great! But I will only need the list of
worksheets from each workbook. Can you provide some
assistance on that ???


The subroutine Demo below will take a folder path as an argument and return
a list of all Excel files (along with each file's worksheets) to the Debug
window. To use it, just enter this in the Debug window (or call it from
code):

Demo "C:\" '/ change this to whatever folder you want to use


Sub Demo(rsFolderPath As String)
Dim fso As Object
Dim fil As Object
Dim vWSNames As Variant
Dim v As Variant

Set fso = CreateObject("Scripting.FileSystemObject")

For Each fil In fso.GetFolder(rsFolderPath).Files
If StrComp(fil.Type, "Microsoft Excel " & _
"Worksheet", vbTextCompare) = 0 Then
Debug.Print fil.Path
vWSNames = mvGetWSNames(fil.Path)
For Each v In vWSNames
Debug.Print " " & CStr(v)
Next v
End If
Next fil

Set fso = Nothing
End Sub

Private Function mvGetWSNames(rsWBPath As String) _
As Variant
Dim adCn As Object
Dim axCat As Object
Dim axTab As Object
Dim asSheets() As String
Dim nShtNum As Integer

Set adCn = CreateObject("ADODB.Connection")
Set axCat = CreateObject("ADOX.Catalog")

With adCn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB" & _
".4.0;Data Source=" & rsWBPath & ";Extended " & _
"Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
.CursorLocation = 3
.Open
End With

Set axCat.ActiveConnection = adCn

For Each axTab In axCat.Tables
ReDim Preserve asSheets(0 To nShtNum)
asSheets(nShtNum) = Left$(axTab.Name, _
Len(axTab.Name) - 1)
nShtNum = nShtNum + 1
Next axTab

mvGetWSNames = asSheets

Set axCat = Nothing
adCn.Close
Set adCn = Nothing
End Function


There is no error handling, so you'd probably want to add some in the case
of a bad folder path or some unexpected error.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]



  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Directory List of Excel Files

My opologees for not being clear. I will have a summary
spreadsheet open, that will be gathering data from 400
excel files, each of which will have an unknown number of
worksheets (but each sheet will be identical in the
layout). I need to open 1 excel file at a time (your
code you pointed to me early does that!) then I need to
get a list of worksheet names from that workbook and use
that info in the other workbook I have open (name
summary.xls).

I can not figure this out as I will also have summary.xls
open and I will be opening and closing all the workbooks
one at a time to extact the data.


-----Original Message-----
Try this

Sub test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file

(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles

(i))
Cells(i, 3).Value = FileLen(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message

...
What you have is great! But I will only need the list

of
worksheets from each workbook. Can you provide some
assistance on that ???

-----Original Message-----
Try to understand this example
http://www.rondebruin.nl/copy3.htm

Post back if you need help

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message

...
Is there a way, through VB, to get a list of excel

files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do

want I
need anyway!

Any help would be great!!!


.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Directory List of Excel Files

Oops

You say worksheets

See Jake's code

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Try this

Sub test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles(i))
Cells(i, 3).Value = FileLen(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ...
What you have is great! But I will only need the list of
worksheets from each workbook. Can you provide some
assistance on that ???

-----Original Message-----
Try to understand this example
http://www.rondebruin.nl/copy3.htm

Post back if you need help

--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message

...
Is there a way, through VB, to get a list of excel

files
from a folder and loop through that list???

I am looking at the "Directory" command but can not
figure out the syntax, and I don't think it can do

want I
need anyway!

Any help would be great!!!


.





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
Combo box with list of xls files in a directory excelguy Excel Discussion (Misc queries) 0 November 27th 06 02:53 PM
List of Files in A Directory JaneC Excel Discussion (Misc queries) 2 February 18th 06 12:11 PM
list box- list all files ina directory suee Excel Programming 9 April 7th 04 02:32 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
Printing .pdf files from directory from excel Murray Williams Excel Programming 0 August 28th 03 11:11 PM


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