PC Review


Reply
Thread Tools Rate Thread

Count all "xlsx" fromat files in a Folder

 
 
K
Guest
Posts: n/a
 
      25th Nov 2008
Hi all, I am working in Excel 2007 and I want macro to count all
"xlsx" fromat files in a folder and put that total count number in
Range("A1"). I found macro (see below) but I am getting error message
on line "With Application.FileSearch" saying "Run-time error 445 -
Object doesn't support this action" Please can any friend can help me
on this.

Sub test()
Dim foldername As String
foldername = "C:\Data"
* * With Application.FileSearch
* * * * .NewSearch
* * * * .LookIn = foldername
* * * * .SearchSubFolders = False
* * * * .FileType = msoFileTypeExcelWorkbooks
* * * * If .Execute() > 0 Then
* * * * * * MsgBox .FoundFiles.Count & " Excel files were found"
* * * * Else
* * * * * * MsgBox "There were no files found."
* * * * End If
* * End With
End Sub
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      25th Nov 2008
FileSearch has been dropped for Excel 2007.

Try

Sub test()
Dim foldername As String
Dim FSO As Object
Dim fldr As Object
Dim file As Object
Dim cnt As Long

foldername = "C:\Data"
Set FSO = CreateObject("Scripting.FilesystemObject")
Set fldr = FSO.GetFolder(foldername)
For Each file In fldr.Files

If file.Type Like "*Microsoft Office Excel*" Then

cnt = cnt + 1
End If
Next file

Set file = Nothing
Set fldr = Nothing
Set FSO = Nothing

Range("A1").Value = cnt
End Sub



--
__________________________________
HTH

Bob

"K" <(E-Mail Removed)> wrote in message
news:d780f418-096c-4513-8b84-(E-Mail Removed)...
Hi all, I am working in Excel 2007 and I want macro to count all
"xlsx" fromat files in a folder and put that total count number in
Range("A1"). I found macro (see below) but I am getting error message
on line "With Application.FileSearch" saying "Run-time error 445 -
Object doesn't support this action" Please can any friend can help me
on this.

Sub test()
Dim foldername As String
foldername = "C:\Data"
With Application.FileSearch
..NewSearch
..LookIn = foldername
..SearchSubFolders = False
..FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
MsgBox .FoundFiles.Count & " Excel files were found"
Else
MsgBox "There were no files found."
End If
End With
End Sub


 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      25th Nov 2008
xl2007 dropped .FileSearch from its Library << it is not available
That's all i can tell you; sorry

"K" wrote:

> Hi all, I am working in Excel 2007 and I want macro to count all
> "xlsx" fromat files in a folder and put that total count number in
> Range("A1"). I found macro (see below) but I am getting error message
> on line "With Application.FileSearch" saying "Run-time error 445 -
> Object doesn't support this action" Please can any friend can help me
> on this.
>
> Sub test()
> Dim foldername As String
> foldername = "C:\Data"
> With Application.FileSearch
> .NewSearch
> .LookIn = foldername
> .SearchSubFolders = False
> .FileType = msoFileTypeExcelWorkbooks
> If .Execute() > 0 Then
> MsgBox .FoundFiles.Count & " Excel files were found"
> Else
> MsgBox "There were no files found."
> End If
> End With
> End Sub
>

 
Reply With Quote
 
K
Guest
Posts: n/a
 
      25th Nov 2008
On Nov 25, 11:29*am, JMay <J...@discussions.microsoft.com> wrote:
> xl2007 dropped .FileSearch from its Library << it is not available
> That's all i can tell you; sorry
>
>
>
> "K" wrote:
> > Hi all, *I am working in Excel 2007 and I want macro to count all
> > "xlsx" fromat files in a folder and put that total count number in
> > Range("A1"). I found macro (see below) but I am getting error message
> > on line "With Application.FileSearch" saying "Run-time error 445 -
> > Object doesn't support this action" *Please can any friend can help me
> > on this.

>
> > Sub test()
> > Dim foldername As String
> > foldername = "C:\Data"
> > * * With Application.FileSearch
> > * * * * .NewSearch
> > * * * * .LookIn = foldername
> > * * * * .SearchSubFolders = False
> > * * * * .FileType = msoFileTypeExcelWorkbooks
> > * * * * If .Execute() > 0 Then
> > * * * * * * MsgBox .FoundFiles.Count & " Excel files were found"
> > * * * * Else
> > * * * * * * MsgBox "There were no files found."
> > * * * * End If
> > * * End With
> > End Sub- Hide quoted text -

>
> - Show quoted text -


Thanks lot bob
 
Reply With Quote
 
K
Guest
Posts: n/a
 
      25th Nov 2008
Just small question with you bob that at the moment your code is
counting all excel files in a folder. But how can i specify it to
just count "xlsx" excel format files in folder.

 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      25th Nov 2008
Bob, how would one search by extension type, say for example -- only .xlsm ?


"Bob Phillips" wrote:

> FileSearch has been dropped for Excel 2007.
>
> Try
>
> Sub test()
> Dim foldername As String
> Dim FSO As Object
> Dim fldr As Object
> Dim file As Object
> Dim cnt As Long
>
> foldername = "C:\Data"
> Set FSO = CreateObject("Scripting.FilesystemObject")
> Set fldr = FSO.GetFolder(foldername)
> For Each file In fldr.Files
>
> If file.Type Like "*Microsoft Office Excel*" Then
>
> cnt = cnt + 1
> End If
> Next file
>
> Set file = Nothing
> Set fldr = Nothing
> Set FSO = Nothing
>
> Range("A1").Value = cnt
> End Sub
>
>
>
> --
> __________________________________
> HTH
>
> Bob
>
> "K" <(E-Mail Removed)> wrote in message
> news:d780f418-096c-4513-8b84-(E-Mail Removed)...
> Hi all, I am working in Excel 2007 and I want macro to count all
> "xlsx" fromat files in a folder and put that total count number in
> Range("A1"). I found macro (see below) but I am getting error message
> on line "With Application.FileSearch" saying "Run-time error 445 -
> Object doesn't support this action" Please can any friend can help me
> on this.
>
> Sub test()
> Dim foldername As String
> foldername = "C:\Data"
> With Application.FileSearch
> ..NewSearch
> ..LookIn = foldername
> ..SearchSubFolders = False
> ..FileType = msoFileTypeExcelWorkbooks
> If .Execute() > 0 Then
> MsgBox .FoundFiles.Count & " Excel files were found"
> Else
> MsgBox "There were no files found."
> End If
> End With
> End Sub
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      25th Nov 2008
Change

If file.Type Like "*Microsoft Office Excel*" Then

to

If file.Type Like "*Microsoft Office Excel W*" Then

--
__________________________________
HTH

Bob

"K" <(E-Mail Removed)> wrote in message
news:0281e78f-9d5d-417e-9307-(E-Mail Removed)...
> Just small question with you bob that at the moment your code is
> counting all excel files in a folder. But how can i specify it to
> just count "xlsx" excel format files in folder.
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      25th Nov 2008
Like so

Sub test()
Dim foldername As String
Dim FSO As Object
Dim fldr As Object
Dim file As Object
Dim cnt As Long

foldername = "C:\Data"
Set FSO = CreateObject("Scripting.FilesystemObject")
Set fldr = FSO.GetFolder(foldername)
For Each file In fldr.Files

If Mid$(file.Name, InStrRev(file.Name, ".") + 1) = "xlsm" Then

cnt = cnt + 1
End If
Next file

Set file = Nothing
Set fldr = Nothing
Set FSO = Nothing

Range("A1").Value = cnt
End Sub



--
__________________________________
HTH

Bob

"JMay" <(E-Mail Removed)> wrote in message
news:A37EFFA9-8D81-4199-98EB-(E-Mail Removed)...
> Bob, how would one search by extension type, say for example -- only
> .xlsm ?
>
>
> "Bob Phillips" wrote:
>
>> FileSearch has been dropped for Excel 2007.
>>
>> Try
>>
>> Sub test()
>> Dim foldername As String
>> Dim FSO As Object
>> Dim fldr As Object
>> Dim file As Object
>> Dim cnt As Long
>>
>> foldername = "C:\Data"
>> Set FSO = CreateObject("Scripting.FilesystemObject")
>> Set fldr = FSO.GetFolder(foldername)
>> For Each file In fldr.Files
>>
>> If file.Type Like "*Microsoft Office Excel*" Then
>>
>> cnt = cnt + 1
>> End If
>> Next file
>>
>> Set file = Nothing
>> Set fldr = Nothing
>> Set FSO = Nothing
>>
>> Range("A1").Value = cnt
>> End Sub
>>
>>
>>
>> --
>> __________________________________
>> HTH
>>
>> Bob
>>
>> "K" <(E-Mail Removed)> wrote in message
>> news:d780f418-096c-4513-8b84-(E-Mail Removed)...
>> Hi all, I am working in Excel 2007 and I want macro to count all
>> "xlsx" fromat files in a folder and put that total count number in
>> Range("A1"). I found macro (see below) but I am getting error message
>> on line "With Application.FileSearch" saying "Run-time error 445 -
>> Object doesn't support this action" Please can any friend can help me
>> on this.
>>
>> Sub test()
>> Dim foldername As String
>> foldername = "C:\Data"
>> With Application.FileSearch
>> ..NewSearch
>> ..LookIn = foldername
>> ..SearchSubFolders = False
>> ..FileType = msoFileTypeExcelWorkbooks
>> If .Execute() > 0 Then
>> MsgBox .FoundFiles.Count & " Excel files were found"
>> Else
>> MsgBox "There were no files found."
>> End If
>> End With
>> End Sub
>>
>>
>>



 
Reply With Quote
 
K
Guest
Posts: n/a
 
      25th Nov 2008
On Nov 25, 12:39*pm, "Bob Phillips" <Bob...@somewhere.com> wrote:
> Like so
>
> Sub test()
> Dim foldername As String
> Dim FSO As Object
> Dim fldr As Object
> Dim file As Object
> Dim cnt As Long
>
> * * foldername = "C:\Data"
> * * Set FSO = CreateObject("Scripting.FilesystemObject")
> * * Set fldr = FSO.GetFolder(foldername)
> * * For Each file In fldr.Files
>
> * * * * If Mid$(file.Name, InStrRev(file.Name, ".") + 1) = "xlsm" Then
>
> * * * * * * cnt = cnt + 1
> * * * * End If
> * * Next file
>
> * * Set file = Nothing
> * * Set fldr = Nothing
> * * Set FSO = Nothing
>
> * * Range("A1").Value = cnt
> End Sub
>
> --
> __________________________________
> HTH
>
> Bob
>
> "JMay" <J...@discussions.microsoft.com> wrote in message
>
> news:A37EFFA9-8D81-4199-98EB-(E-Mail Removed)...
>
>
>
> > Bob, *how would one search by extension type, say for example -- only
> > .xlsm ?

>
> > "Bob Phillips" wrote:

>
> >> FileSearch has been dropped for Excel 2007.

>
> >> Try

>
> >> Sub test()
> >> Dim foldername As String
> >> Dim FSO As Object
> >> Dim fldr As Object
> >> Dim file As Object
> >> Dim cnt As Long

>
> >> * * foldername = "C:\Data"
> >> * * Set FSO = CreateObject("Scripting.FilesystemObject")
> >> * * Set fldr = FSO.GetFolder(foldername)
> >> * * For Each file In fldr.Files

>
> >> * * * * If file.Type Like "*Microsoft Office Excel*" Then

>
> >> * * * * * * cnt = cnt + 1
> >> * * * * End If
> >> * * Next file

>
> >> * * Set file = Nothing
> >> * * Set fldr = Nothing
> >> * * Set FSO = Nothing

>
> >> * * Range("A1").Value = cnt
> >> End Sub

>
> >> --
> >> __________________________________
> >> HTH

>
> >> Bob

>
> >> "K" <kamranr1...@yahoo.co.uk> wrote in message
> >>news:d780f418-096c-4513-8b84-(E-Mail Removed)....
> >> Hi all, *I am working in Excel 2007 and I want macro to count all
> >> "xlsx" fromat files in a folder and put that total count number in
> >> Range("A1"). I found macro (see below) but I am getting error message
> >> on line "With Application.FileSearch" saying "Run-time error 445 -
> >> Object doesn't support this action" *Please can any friend can help me
> >> on this.

>
> >> Sub test()
> >> Dim foldername As String
> >> foldername = "C:\Data"
> >> With Application.FileSearch
> >> ..NewSearch
> >> ..LookIn = foldername
> >> ..SearchSubFolders = False
> >> ..FileType = msoFileTypeExcelWorkbooks
> >> If .Execute() > 0 Then
> >> MsgBox .FoundFiles.Count & " Excel files were found"
> >> Else
> >> MsgBox "There were no files found."
> >> End If
> >> End With
> >> End Sub- Hide quoted text -

>
> - Show quoted text -


Thanks again Bob for all your help and time
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Nov 2008
One way:

Option Explicit
Sub test()
Dim foldername As String
Dim FSO As Object
Dim fldr As Object
Dim file As Object
Dim cnt As Long


foldername = "C:\Data"

Set FSO = CreateObject("Scripting.FilesystemObject")
Set fldr = FSO.GetFolder(foldername)
For Each file In fldr.Files
If LCase(file.Name) Like "*.xlsx" Then
cnt = cnt + 1
End If
Next file

Set file = Nothing
Set fldr = Nothing
Set FSO = Nothing

Range("A1").Value = cnt
End Sub

K wrote:
>
> Just small question with you bob that at the moment your code is
> counting all excel files in a folder. But how can i specify it to
> just count "xlsx" excel format files in folder.


--

Dave Peterson
 
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
Files are copied to local "Nethood" folder instead of remote shared folder under "My Network place" ? Wolfgang Hercker Microsoft Windows 2000 Networking 1 23rd Aug 2006 08:54 AM
Files are copied to local "Nethood" folder instead of remote shared folder under "My Network place" ? Wolfgang Hercker Windows XP Help 0 23rd Aug 2006 08:29 AM
Files are copied to local "Nethood" folder instead of remote shared folder under "My Network place" ? Wolfgang Hercker Microsoft Windows 2000 0 23rd Aug 2006 08:29 AM
Files are copied to local "Nethood" folder instead of remote shared folder under "My Network place" ? Wolfgang Hercker Windows XP General 0 23rd Aug 2006 08:29 AM
Error messages "There are no files in the folder" and "Server "" Timed Out" =?Utf-8?B?U2Ft?= Microsoft Frontpage 1 5th Feb 2004 10:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 AM.