文件浏览窗口的一个问题
Private Sub Command1_Click()
Set spShell = CreateObject("Shell.Application")
Set spFolder = spShell.BrowseForFolder(0, "选择目录:", 0, "C:\Scripts")
Set spFolderItem = spFolder.Self
spPath = spFolderItem.Path
spPath = Replace(spPath, "", "")
Print spPath
End Sub
这段代码生成一个文件浏览窗口,如果点了取消返回的是Nothing,程序就会出错,怎么处理啊?
[解决办法]
完美解决楼主的疑问:
Private Sub Command1_Click()
Set spShell = CreateObject("Shell.Application")
Set spfolder = spShell.BrowseForFolder(0, "选择目录:", 0, "C:\Scripts")
If spfolder Is Nothing Then Exit Sub
Set spFolderItem = spfolder.Self
spPath = spFolderItem.Path
spPath = Replace(spPath, "", "")
Print spPath
End Sub