作者:乔山办公网日期:
返回目录:excel表格制作
可以利用VBA判断指百定路径下是否存在某个文件夹。
工具:Office2013
方法如下度:
1.利用VBA判定当前工回作簿所在文件夹中,是否存在一个“鱼木混猪”的文件夹:
2.在Excel中按下Alt+F11,输入代码如下:
3.F5执行代码,如果文件夹存在,就显示如下图:
不存答在,怎会弹窗显示“不存在”。
可以使用如下几个函数来判断636f7079e799bee5baa6e79fa5e98193332
Function ExistsFile_UseFso(strPath As String) As BooleanDim fsoSet fso = CreateObject("Scripting.FileSystemObject")
ExistsFile_UseFso = fso.FileExists(strPath)
Set fso = Nothing
End Function
Function FolderExists_UseFso(strPath As String) As BooleanDim fsoSet fso = CreateObject("Scripting.FileSystemObject")
FolderExists_UseFso = fso.FolderExists(strPath)
Set fso = Nothing
End Function
Function FileOrFolderExists_UseDir(strPath As String) As Boolean
'注意,使用 DIR 函数来检测文件或者文件夹是否存在在局域网环境下
'由于访问权限问题可能会出错
If Dir(strPath) = "" Then
1和0
楼主应该是要判断文件zhidao不是文件夹吧?如果是文件回就用
Dim MyFile As Object
Set MyFile = CreateObject("Scripting.FileSystemObject")
If MyFile.FileExists("D:\logo.gif" ) = True Then
MsgBox "文件存在"
Else
MsgBox "文件不存在"
End If
如果是文件夹就用答1楼的方法.
if dir(dPath,vbDirectory)<>"" then
msgbox "存在"
end if