我有一个调用 Chrome 的宏,但是在不同的机器上部署这段代码会被每台机器上不同的 chrome 的完整文件路径破坏。为了缓解这种情况,我想一次性搜索“chrome.exe”并将文件路径存储为变量。以下似乎可行,但是递归会产生堆栈空间问题(运行时错误 28)。
这似乎是一个如此简单的操作,并且递归搜索遍布通常的论坛,但我无法正确!
Function Recurse(sPath As String) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Application.ScreenUpdating = False
Set myFolder = FSO.GetFolder("C:\")
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If myFile.Name = "chrome.exe" Then
Debug.Print myFile.Name & " in " & myFile.Path
Exit For
End If
Next
Recurse = Recurse(mySubFolder.Path)
Next
Application.ScreenUpdating = True
End Function
Sub ChromeSearch()
Call Recurse("C:\")
End Sub