View Single Post
  #22   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Sub cannot run (Error 5)

Max,

Private Sub CommandButton1_Click()
Dim FileCount As Long

'FileCount = ListFilesWith_DIR(ActiveSheet.Range("B1"), "D:\Program
Files\Erlang\CalcA", "*.*")
FileCount = ListFilesWith_DIR(ActiveSheet.Range("B1"), "C:", "*.*")

MsgBox FileCount & " files found.", vbOKOnly, "Results"

End Sub

Private Function ListFilesWith_DIR(argStartRange As Range, _
ByVal argFolderPath As String, _
Optional argFilter As String = "*.*") _
As Long

Dim FileName As String
Dim i As Integer

If Right(argFolderPath, 1) < "\" Then argFolderPath = argFolderPath & "\"

FileName = Dir(argFolderPath & argFilter, vbNormal)

Do While FileName < ""
With argStartRange
.Offset(i, 0).Value = FileName
.Offset(i, 1).Value = FileDateTime(argFolderPath & FileName)
.Offset(i, 2).Value = FileLen(argFolderPath & FileName)
End With

i = i + 1
FileName = Dir()
Loop

'Return the number of files found
ListFilesWith_DIR = i

End Function

NickHK




"Max" wrote in message
...
I had a look there, but I think its out of my depth to produce something
meaningful (I'm still a vba newbie). Do you have some sample code at hand
which could illustrate the same functionality as that of the Sub
ListFiles02() [I plucked the sub from one of the posts here]. Thanks.
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--
"NickHK" wrote in message
...
Max,
VBA Help has examples.

NickHK