check if a folder is open (vba)
问题 I am trying to check whether a specific folder is open or not using VBA . I have found this code: Sub test1() Dim OpenFold As Variant Dim oShell As Object Dim Wnd As Object Dim strFolder OpenFold = "mysubfolder" strFolder = "U:\myfolder\" & OpenFold Set oShell = CreateObject("Shell.Application") For Each Wnd In oShell.Windows If Wnd.Document.Folder.Self.Path = OpenFold Then 'this is where it gives me the error Exit Sub ' Folder is open - exit this Sub End If Next Wnd Application.ThisWorkbook