我正在使用以下代码打开特定文件夹。
我需要在打开之前检查该文件夹或子文件夹是否已在 Windows 资源管理器中打开,以防止重复。
感谢任何有用的评论和答案。
Sub Prevent_opening_duplicate_folder ()
Dim Folder_Path As String
Folder_Path = "D:\Users\Waleed\Desktop\Test"
Shell "explorer """ & Folder_Path & ""
DoEvents
End Sub
这将做到:
Function isFolderOpen(Path As String) As Boolean
Dim sh As Object, w As Object, Document
Set sh = CreateObject("shell.application")
For Each w In sh.Windows
If w.Name = "Windows Explorer" Or w.Name = "File Explorer" Then
Debug.Print w.Document.folder.self.Path
Set Document = w.Document
If Document.folder.self.Path = Path Then
isFolderOpen = True
Exit Function
End If
End If
Next
End Function
Function isFolderOpenOrSubFolder(Path As String) As Boolean
Dim sh As Object, w As Object, Document
Set sh = CreateObject("shell.application")
For Each w In sh.Windows
If w.Name = "Windows Explorer" Or w.Name = "File Explorer" Then
Set Document = w.Document
If Left(Document.folder.self.Path, Len(Path)) = Path Then
isFolderOpenOrSubFolder = True
Exit Function
End If
End If
Next
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句