Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Count files in folder

Hello,

I want to create a macro that will go to a folder, count the excel
documents in it (There will only be excel documents in it if that
helps), go back to my original document and enter the number of files
in a cell.

Is this possible?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Count files in folder

Thanks to Dave Petersen for helping me with a similar situation a month
or two ago. This should work:

Private Sub CountFiles()
Dim i As Long
Dim FS As FileSearch

Set FS = Application.FileSearch

With FS
.LookIn = "C:\" 'change this to your folder
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
Range("A1") = FS.FoundFiles.Count
End If
End With
End Sub



*** Sent via Developersdex http://www.developersdex.com ***
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Count files in folder

The folder name will either have to be passed to the macro by another macro

Sub gmunroMacro(sFolderName As String)
Dim i As Integer

Dim sResult As String

i = 0

sResult = Dir(sFolderName & "\*.*")

Do While sResult < ""
i = i + 1
sResult = Dir()
Loop

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

or be hard coded into the macro

Sub gmunroMacro()
Dim i As Integer

Dim sResult As String

i = 0

sResult = Dir("C:\gmunroFolder\*.*")

Do While sResult < ""
i = i + 1
sResult = Dir()
Loop

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


gmunro wrote in message
.com...
Hello,

I want to create a macro that will go to a folder, count the excel
documents in it (There will only be excel documents in it if that
helps), go back to my original document and enter the number of files
in a cell.

Is this possible?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Count files in folder

One more way:

Option Explicit
Sub testme()
Dim FSO As Object
Dim myFolder As String

myFolder = "C:\my documents\excel"

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(myFolder) Then
activesheet.range("a1").value = FSO.GetFolder(myFolder).Files.Count
End If

End Sub

gmunro wrote:

Hello,

I want to create a macro that will go to a folder, count the excel
documents in it (There will only be excel documents in it if that
helps), go back to my original document and enter the number of files
in a cell.

Is this possible?


--

Dave Peterson
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
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
Count files in a folder Wanna Learn Excel Discussion (Misc queries) 4 July 9th 08 05:46 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
Count files in a Folder! SpeeD72 Excel Programming 1 September 11th 03 07:18 PM
Count files in a Folder! Bob Phillips[_5_] Excel Programming 0 September 11th 03 06:38 PM


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