Sunday, 25 August 2013

Declaring a variant type more specifically as a collection

Declaring a variant type more specifically as a collection

This is an extract of a sub-routine I use lot:
Private Sub DeleteFilesNotCreatedToday(myTargetFolder As String)
Dim myFolder
Dim myFile
Dim YesterdayDate As Date
YesterdayDate = Date
Set myFolder =
CreateObject("Scripting.FileSystemObject").GetFolder(myTargetFolder).Files
For Each myFile In myFolder
...
...
Next myFile
Why can't I declare myFolder more specifically instead of variant - or can
I? I've tried declaring it as a collection but it errors...
Private Sub DeleteFilesNotCreatedToday(myTargetFolder As String)
Dim myFolder As Collection
Dim myFile
Dim YesterdayDate As Date
YesterdayDate = Date
Set myFolder =
CreateObject("Scripting.FileSystemObject").GetFolder(myTargetFolder).Files
For Each myFile In myFolder
...
...
Next myFile

No comments:

Post a Comment