我找到了一个帖子,关于check if a folder is open (vba)的代码在堆栈上溢出。
如果文件夹已经打开,在屏幕顶部显示它怎么办?
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.Name = "Windows Explorer" Then
If Wnd.Document.Folder.Self.Path = strFolder Then Exit Sub
End If
Next Wnd
Application.ThisWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
End Sub