vba判断文件是否存在的两种方法
2013-10-12 12:56
405 查看
方法1. 用VBA自带的dir()判断,代码如下:
在 Microsoft Windows 中, Dir 支持多字符 (*)和单字符 (?)
的通配符来指定多重文件
方法2. 用Windows的文件系统函数进行判断,代码如下:
在 Microsoft Windows 中, Dir 支持多字符 (*)和单字符 (?)
的通配符来指定多重文件
Function IsFileExists(ByVal strFileName As String) As Boolean If Dir(strFileName, 16) <> Empty Then IsFileExists = True Else IsFileExists = False End If End Function Sub Run() If IsFileExists("D:\vba\abc.txt") = True Then ' 文件存在时的处理 MsgBox "文件存在!" Else ' 文件不存在时的处理 MsgBox "文件不存在!" End If End Sub
方法2. 用Windows的文件系统函数进行判断,代码如下:
Function IsFileExists(ByVal strFileName As String) As Boolean Dim objFileSystem As Object Set objFileSystem = CreateObject("Scripting.FileSystemObject") If objFileSystem.fileExists(strFileName) = True Then IsFileExists = True Else IsFileExists = False End If End Function Sub Run() If IsFileExists("D:\vba\abc.txt") = True Then ' 文件存在时的处理 MsgBox "文件存在!" Else ' 文件不存在时的处理 MsgBox "文件不存在!" End If End Sub
相关文章推荐
- vba判断文件是否存在的两种方法
- C语言判断文件夹或者文件是否存在的方法
- Python判断文件或文件夹是否存在的三种方法
- Shell 判断文件是否存在的方法
- C#判断文件是否存在方法
- PHP判断远程文件是否存在的几种方法
- 判断文件是否存在的方法
- SQLITE 创建表 并判断表是否存在的两种方法
- C语言中判断文件是否存在的方法详解
- VC下判断文件是否存在的方法
- 【Python那些事儿】判断文件/文件夹是否存在的方法
- VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
- My way on Linux - [Shell基础] - Bash Shell中判断文件、目录是否存在或者判断其是否具有某类属性(权限)的常用方法
- C语言判断文件夹或者文件是否存在的方法
- C#判断文件是否存在方法
- 两种不同方法判断Excel表格中是否存在指定数值
- C语言判断文件夹或者文件是否存在的方法
- win8 metro开发中,判断文件是否存在的方法
- linux下判断文件和目录是否存在的方法(总结)
- PHP判断网络文件是否存在的方法