【发布时间】:2017-02-16 21:25:05
【问题描述】:
我在取消选择文件夹时遇到基本错误。我只想在按下取消按钮时退出 Sub。
我正在使用以下代码
Set recsFolder = fso.GetFolder(Functions.GetFolder("C:\"))
Function GetFolder(strPath As String) As String
Dim Fldr As FileDialog
Dim sItem As String
Set Fldr = Application.FileDialog(msoFileDialogFolderPicker)
With Fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set Fldr = Nothing
End Function
【问题讨论】:
-
当你点击调试时你落在哪一行?
-
这是因为您的 recsFolder 功能失效。尝试将其插入函数中,然后他们将 Fldr 与 false 进行比较?或者按取消键是什么