【发布时间】:2017-10-30 12:02:20
【问题描述】:
我正在尝试使用 FileSystemObject 打开一个文件,但是当我尝试运行它时,系统什么也没做。不显示调试,没有运行时错误,不编译。它只是保持原样。 我还检查了参考资料中的“MS Scripting Runtime”。 以下是我为此使用的代码:
Sub fsoobject()
Dim fso As New FileSystemObject, f As Folder, sf As Folder, myFile As File
Set f = fso.GetFolder("C:\Users\jpmehta\Desktop")
For Each sf In f.SubFolders
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If myFile.Name Like "Done" Then
MsgBox myFile.Name
Exit For
End If
Next
MsgBox "Else"
Next
Next
End Sub
【问题讨论】:
-
用
sf替换myFolder -
仍然没有发生 :(
-
唯一的
Like "Done"是“完成” - 也许你需要通配符。 -
如SJR所说,wildcard如
Like "*Done*" -
@JayyM 不应该
For Each mySubFolder In myFolder.SubFolders是For Each mySubFolder In sf.SubFolders吗?
标签: excel filesystemobject fso vba