kaixuan1115 / notes

笔记收录
6 stars 0 forks source link

VBS 选择文件/文件夹对话框 #8

Closed xiaokaixuan closed 5 years ago

xiaokaixuan commented 5 years ago
Function SelectFile()
    Set oExec = CreateObject("WScript.Shell")._
    Exec("mshta.exe ""about:<input type=file id=path><script>path.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(path.value);close();resizeTo(0,0);</script>""")
    StrLine = oExec.StdOut.ReadAll
    Pos = InStr(StrLine, Chr(13))
    If Pos <= 0 Then
        SelectFile = ""
    Else
        SelectFile = Left(StrLine, Pos - 1)
    End If
End Function

Function SelectFolder(default)
    If IsNull(default) Then
        default = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
    End If
    Set Folder = CreateObject("Shell.Application").BrowseForFolder(0, "", 0, default)
    If Folder Is Nothing Then
        SelectFolder = ""
    Else
        SelectFolder = Folder.Self.Path
    End If
End Function

MsgBox SelectFile()
MsgBox SelectFolder(Null)