这是我经常使用的子程序的摘录:
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
为什么我不能myFolder
更具体地声明而不是变体 - 或者我可以吗?我试过将它声明为一个集合,但它出错了......
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