当前位置:首页 > 点滴记录 > 正文

VB 浏览文件夹 记录一下

VB 浏览文件夹 记录一下

Public Function ShowFolderDialog( As String'/最简单的显示文件夹选择对话框方法Dim spShell, spFol...

Public Function ShowFolderDialog() As String


'/最简单的显示文件夹选择对话框方法


Dim spShell, spFolder, spFolderItem, spPath As String


Const WINDOW_HANDLE = 0


Const NO_OPTIONS = 0


Set spShell = CreateObject("Shell.Application")


Set spFolder = spShell.BrowseForFolder(WINDOW_HANDLE, "选择目录:", NO_OPTIONS, "C:\Scripts")


If spFolder Is Nothing Then


   ShowFolderDialog = ""


Else


    Set spFolderItem = spFolder.Self


    spPath = spFolderItem.path


    spPath = Replace(spPath, "\", "\")


   ShowFolderDialog = spPath


End If


End Function


Private Sub Command1_Click()


Dim path As String


path = ShowFolderDialog()


MsgBox IIf(Len(path) = 0, "你点击了取消按钮!", "你选择的文件夹是:" & path)


End Sub


发表评论

最新文章

取消
扫码支持 支付码