【发布时间】:2021-09-11 21:19:08
【问题描述】:
我正在使用以下代码让用户提供 SFTP 目录的路径,以便记录在此类供应商项目的清单中。我在为我知道该目录存在的项目填充路径时遇到问题,所以我 99% 确定问题是我没有对该目录的权限(我知道我没有)。
'Check if the SFTP exists already
If MsgBox("Does the SFTP for this vendor/campaign already exist?", vbYesNo, "SFTP Exists?") = vbYes Then
'Prompt for the network folder
Do While SFTP = ""
SFTP = Trim(InputBox("Please provide the folder path to the report's SFTP.", "New Campaign/Vendor SFTP", " "))
Select Case SFTP
Case "", " "
If MsgBox("No path provided for the new campagin/vendor SFTP folder. Would you like to retry providing the SFTP (clicking 'No' " & _
"will leave the SFTP folder field empty for now).", vbYesNo, "No Value Provided") = vbNo Then
SFTP = "ignore"
Else
SFTP = ""
End If
Case Else
'Potentially valid folder, check if it exists already
If Dir(SFTP, vbDirectory) = "" Then
'Provided path doesn't exist, prompt user to retry
If MsgBox("The specified path (" & SFTP & ") does not exist. Would you like to retry providing the SFTP (clicking 'No' " & _
"will leave the SFTP folder field empty for now).", vbYesNo, "Create the Folder?") = vbYes Then
SFTP = ""
Else
SFTP = "ignore"
End If
End If 'the folder exists no action needed
End Select
Loop
Else
'Set SFTP to ignore so that we leave the field blank downstream
SFTP = "ignore"
End If
特别是我得到运行时错误 52。
有没有办法使用DIR 或类似的东西来检查目录是否存在不需要文件夹的权限?
我想保留该验证以避免诸如拼写错误之类的事情弄乱库存表(进一步的路径用于在工作表中创建链接,一条错误的路径显然会搞砸),但我不能始终确保填写路径的人有权访问该文件夹。
【问题讨论】:
-
引用“Microsoft Scripting Runtime”..不确定..检查这是否有效...
Dim fso As Scripting.FileSystemObject ... Set fso = New Scripting.FileSystemObject然后If fso.FolderExists(FolderPathHere ending with \) Then -
Naresh,如果你想把它作为答案,那就太好了:) 给你信用
-
不确定它是否适用于受限制的文件夹访问.. 作为评论提到.. :).. 请仅在有效的情况下接受/支持答案,以便其他人知道。跨度>
标签: vba validation directory