PC Review


Reply
Thread Tools Rate Thread

counting xls files in a folder

 
 
dstiefe
Guest
Posts: n/a
 
      13th Aug 2009
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



 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      13th Aug 2009
Look in the vba help index for DIR


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"dstiefe" <(E-Mail Removed)> wrote in message
news:0911EE2B-C472-40FD-9F14-(E-Mail Removed)...
> 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
>
>
>


 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Aug 2009
Have you tried the DIR option i posted///
--
If this post helps click Yes
---------------
Jacob Skaria


"dstiefe" wrote:

> 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
>
>
>

 
Reply With Quote
 
dstiefe
Guest
Posts: n/a
 
      13th Aug 2009
it didn't work...



"Jacob Skaria" wrote:

> Have you tried the DIR option i posted///
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "dstiefe" wrote:
>
> > 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
> >
> >
> >

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Aug 2009
Note the slash after the folder name
strFolder = "c:\temp\"

If this post helps click Yes
---------------
Jacob Skaria


"dstiefe" wrote:

> it didn't work...
>
>
>
> "Jacob Skaria" wrote:
>
> > Have you tried the DIR option i posted///
> > --
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "dstiefe" wrote:
> >
> > > 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
> > >
> > >
> > >

 
Reply With Quote
 
dstiefe
Guest
Posts: n/a
 
      13th Aug 2009
that worked..

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

Thank you1!!

"Jacob Skaria" wrote:

> Note the slash after the folder name
> strFolder = "c:\temp\"
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "dstiefe" wrote:
>
> > it didn't work...
> >
> >
> >
> > "Jacob Skaria" wrote:
> >
> > > Have you tried the DIR option i posted///
> > > --
> > > If this post helps click Yes
> > > ---------------
> > > Jacob Skaria
> > >
> > >
> > > "dstiefe" wrote:
> > >
> > > > 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
> > > >
> > > >
> > > >

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Aug 2009
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
---------------
Jacob Skaria


"dstiefe" wrote:

> that worked..
>
> how would i loop through the xls files in the folder and open them?
>
> Thank you1!!
>
> "Jacob Skaria" wrote:
>
> > Note the slash after the folder name
> > strFolder = "c:\temp\"
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "dstiefe" wrote:
> >
> > > it didn't work...
> > >
> > >
> > >
> > > "Jacob Skaria" wrote:
> > >
> > > > Have you tried the DIR option i posted///
> > > > --
> > > > If this post helps click Yes
> > > > ---------------
> > > > Jacob Skaria
> > > >
> > > >
> > > > "dstiefe" wrote:
> > > >
> > > > > 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
> > > > >
> > > > >
> > > > >

 
Reply With Quote
 
dstiefe
Guest
Posts: n/a
 
      13th Aug 2009

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?
"Jacob Skaria" wrote:

> 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
> ---------------
> Jacob Skaria
>
>
> "dstiefe" wrote:
>
> > that worked..
> >
> > how would i loop through the xls files in the folder and open them?
> >
> > Thank you1!!
> >
> > "Jacob Skaria" wrote:
> >
> > > Note the slash after the folder name
> > > strFolder = "c:\temp\"
> > >
> > > If this post helps click Yes
> > > ---------------
> > > Jacob Skaria
> > >
> > >
> > > "dstiefe" wrote:
> > >
> > > > it didn't work...
> > > >
> > > >
> > > >
> > > > "Jacob Skaria" wrote:
> > > >
> > > > > Have you tried the DIR option i posted///
> > > > > --
> > > > > If this post helps click Yes
> > > > > ---------------
> > > > > Jacob Skaria
> > > > >
> > > > >
> > > > > "dstiefe" wrote:
> > > > >
> > > > > > 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
> > > > > >
> > > > > >
> > > > > >

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      13th Aug 2009
Check whether the file is open or not using the function mentioned in the
link and based on that open

http://support.microsoft.com/default.aspx?kbid=138621

If this post helps click Yes
---------------
Jacob Skaria


"dstiefe" wrote:

>
> 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?
> "Jacob Skaria" wrote:
>
> > 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
> > ---------------
> > Jacob Skaria
> >
> >
> > "dstiefe" wrote:
> >
> > > that worked..
> > >
> > > how would i loop through the xls files in the folder and open them?
> > >
> > > Thank you1!!
> > >
> > > "Jacob Skaria" wrote:
> > >
> > > > Note the slash after the folder name
> > > > strFolder = "c:\temp\"
> > > >
> > > > If this post helps click Yes
> > > > ---------------
> > > > Jacob Skaria
> > > >
> > > >
> > > > "dstiefe" wrote:
> > > >
> > > > > it didn't work...
> > > > >
> > > > >
> > > > >
> > > > > "Jacob Skaria" wrote:
> > > > >
> > > > > > Have you tried the DIR option i posted///
> > > > > > --
> > > > > > If this post helps click Yes
> > > > > > ---------------
> > > > > > Jacob Skaria
> > > > > >
> > > > > >
> > > > > > "dstiefe" wrote:
> > > > > >
> > > > > > > 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
> > > > > > >
> > > > > > >
> > > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting excel files in a folder dstiefe Microsoft Excel Programming 4 13th Aug 2009 04:08 PM
counting words in all docs in a folder Daphne Eze Freeware 4 22nd Jul 2006 07:25 PM
Counting files in a folder Hawki Microsoft Excel Programming 7 14th Apr 2004 05:54 PM
counting files in a folder jefe Microsoft Excel Programming 2 2nd Mar 2004 07:36 PM
counting files Edson Microsoft Windows 2000 CMD Promt 3 22nd Jan 2004 02:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 PM.