exl vb函数 有3个文件夹依次判断文件夹是否存在如果第一个已存在 则停止后面的文件夹判断否则继续判断第二个第三个
可以使用以下的VBA代码来实现这个功能:
Sub CheckFolders()
Dim folderPath1 As String
Dim folderPath2 As String
Dim folderPath3 As String
folderPath1 = "C:\Folder1" '第一个文件夹路径
folderPath2 = "C:\Folder2" '第二个文件夹路径
folderPath3 = "C:\Folder3" '第三个文件夹路径
If Dir(folderPath1, vbDirectory) <> "" Then
MsgBox folderPath1 & " 文件夹已存在"
ElseIf Dir(folderPath2, vbDirectory) <> "" Then
MsgBox folderPath2 & " 文件夹已存在"
ElseIf Dir(folderPath3, vbDirectory) <> "" Then
MsgBox folderPath3 & " 文件夹已存在"
Else
MsgBox "所有文件夹都不存在"
End If
End Sub
在这段代码中,我们首先定义了三个文件夹的路径。然后通过使用Dir函数来判断每个文件夹是否存在。如果第一个文件夹存在,则显示相应的消息并停止后面的文件夹判断。如果第一个文件夹不存在,则继续判断第二个文件夹,以此类推。
你可以根据实际的文件夹路径进行修改。
原文地址: https://www.cveoy.top/t/topic/i9ZD 著作权归作者所有。请勿转载和采集!