检查文件夹是否打开vba,然后在顶部显示

时间:2019-02-13 07:18:16

标签: excel vba

我找到了一个帖子,关于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

0 个答案:

没有答案