Sub cannot run (Error 5)

M

Max

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.
 
N

NickHK

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 said:
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 said:
Max,
VBA Help has examples.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top