counting xls files in a folder

D

dstiefe

someone had given me this code... (see below)...but the "filesearch" option
does not pop up when I start typing the code.. I am using 2007 version...will
that make a difference?

Thank you

Here is another method

Sub test()
folder = "c:\temp"

Set FS = Application.FileSearch
With FS
.NewSearch
.LookIn = folder
.SearchSubFolders = False
'.Filename = "Run"
'.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks

FileCount = .Execute

If FileCount > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
Else
MsgBox "There were no files found."
End If

End With


End Sub
 
J

Jacob Skaria

Note the slash after the folder name
strFolder = "c:\temp\"

If this post helps click Yes
 
D

dstiefe

that worked..

how would i loop through the xls files in the folder and open them?

Thank you1!!
 
J

Jacob Skaria

Try the below and feedback

Sub Macro()
Dim strFolder As String, strFile As String
Dim intCount As Integer
strFolder = "d:\"
strFile = Dir(strFolder & "*.xls", vbNormal)
Do While strFile <> ""
Workbooks.Open strFolder & strFile
intCount = intCount + 1
strFile = Dir
Loop
MsgBox intCount & " files found"
End Sub

If this post helps click Yes
 
D

dstiefe

ok...

how do i skip the xls file that is open

because the spread sheet i am working with is in the folder

and when i run the code it wants to reopen or clsoe the existing file...and
hence stoping my vba code

make sense?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top