GetFolder从私有文件夹返回值

时间:2019-06-13 13:36:26

标签: excel vba

如何使此代码与私有文件夹一起正常使用,例如,如果某人没有读/写访问权限,如何显示正确的错误消息而不是未选择任何文件夹。现在,如果字符串为null,则仅显示未选择的文件夹,但是我想告诉他们有关受保护的文件夹的信息。任何帮助将不胜感激!

Sub TestFunc()
Dim BaseDirectory As String


BaseDirectory = GetFolder()

If (BaseDirectory = vbNullString) Then
MsgBox "No Folder Selected", vbExclamation, "Error"
End If
EndSub

Function GetFolder() As String

    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)

    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
    .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo NextCode
            sItem = .SelectedItems(1)
    End With
    NextCode:
        GetFolder = sItem
        Set fldr = Nothing
End Function

0 个答案:

没有答案