我试图使用FileSystemObject打开一个文件,但是当我试图运行它时,系统什么也不做。没有显示Debug,没有运行时错误,也没有编译。它只会保持原样。我还检查了参考资料中的"MS脚本运行时“。下面是我为此使用的代码:
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发布于 2017-10-30 13:03:25
Sub fsoobject()
Dim fso As New FileSystemObject
dim f As Folder
dim sf As Folder
dim mySubFolder as folder
dim myFile As File
Set f = fso.GetFolder("C:\Users\jpmehta\Desktop")
dim found as boolean 'flag if found
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 mysubfolder.path & "\" & myFile.Name
found = true 'we found it
Exit For 'so stop
End If
Next myFile
if found then exit for 'cascade exit
Next MySubFolder
if found then exit for 'and again
next sf
End Sub发布于 2017-10-30 13:02:20
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 sf.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
Dim File
For Each File In f.Files
If File.Name = "Done.PNG" Then
Call Shell("Explorer.exe """ & File.Path & """", vbNormalFocus)
Exit For
End If
Next
End Sub嗯,我搜索了一下,找到了这个关键字"Shell“来打开一个文件。在应用这段代码之后,现在它成功地执行了.
发布于 2017-10-30 13:10:34
这个密码适用于我。清晰而简单:
Sub fsoobject()
Dim fso As New FileSystemObject, f As Folder, sf As Folder, ssf As Folder,
myFile As File
Set f = fso.GetFolder("C:\Users\tomek\Desktop")
For Each sf In f.SubFolders
Set ssf = sf
For Each myFile In ssf.Files
If myFile.Name Like "Done" Then
Debug.Print myFile.Name
Exit For
End If
Debug.Print "Else:" & myFile.Name
Next
Next
End Subhttps://stackoverflow.com/questions/47014782
复制相似问题