Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Count all "xlsx" fromat files in a Folder

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Count all "xlsx" fromat files in a Folder

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" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Count all "xlsx" fromat files in a Folder

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Count all "xlsx" fromat files in a Folder

Change

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

to

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

--
__________________________________
HTH

Bob

"K" wrote in message
...
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Count all "xlsx" fromat files in a Folder

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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Count all "xlsx" fromat files in a Folder

On Nov 25, 12:58*pm, Dave Peterson wrote:
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


Thanks Dave for you help
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Count all "xlsx" fromat files in a Folder

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" wrote in message
...
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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Count all "xlsx" fromat files in a Folder

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" wrote in message
...
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" wrote in message
...
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





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Count all "xlsx" fromat files in a Folder

On Nov 25, 12:39*pm, "Bob Phillips" 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" wrote in message

...



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" wrote in message
....
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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Count all "xlsx" fromat files in a Folder

Thanks Bob;
FWIW:
Last Comment - When comparing the Count (in Cell A1) to my actual 2007 Data
files, I found the code to produce 1 greater than the actual count. Had to
(on last line) use Range("A1").Value = cnt - 1



"Bob Phillips" 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" wrote in message
...
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" wrote in message
...
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








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count all "xlsx" fromat files in a Folder

Hi Bob-

I have a similar problem, except my Excel 2003 macro used to loop
through files in a folder and run a macro on them (like an update file
macro or something). Now I cannot run that and I have been trying
extremely hard to figure a way around it but I'm completely
lost...here's my old code, any help from anyone please would help :)

Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

With Application.FileSearch
.NewSearch
'Insert path to folder with files to update below
.LookIn = "C:\Documents and Settings\Jennifer
Sturgill\Desktop\ERCI-JS Offline\JUNE VPM MACRO Defender
Files\TESTFILES"
.FileType = msoFileTypeExcelWorkbooks
'.Filename = "Book*.xls"
If .Execute 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults =
Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Application.Run "PERSONAL.xls!VPM_BudgetUpdates2"
Next lCount
End If
End With

On Error GoTo 0


THANKS! J


*** Sent via Developersdex http://www.developersdex.com ***
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Count all "xlsx" fromat files in a Folder

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

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Count all "xlsx" fromat files in a Folder

On Nov 25, 11:29*am, JMay 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
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 prevent Excel 2007 from leaving ".tmp" files in my folder Deb M Excel Discussion (Misc queries) 5 June 4th 09 07:16 PM
Open all excel files in the "volatile" folder [email protected] Excel Programming 1 October 20th 06 07:07 PM
creating an XLS file from " files" data in a Folder Edwin Mashiringwani Excel Discussion (Misc queries) 2 November 19th 05 04:45 PM
"Folder Select" Dialogue - Opening multiple files from selected folder Rob[_26_] Excel Programming 2 September 30th 05 02:47 PM


All times are GMT +1. The time now is 02:58 PM.

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"