View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Doug[_13_] Doug[_13_] is offline
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?