vba 选择文件,文件夹,判断是否存在
作者:互联网
打开文件夹:
Public Function ChooseFolder(Rg As Range)
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
Rg = .SelectedItems(1)
End If
End With
End Function
打开文件:
Public Function ChooseFile(Rg As Range)
With Application.FileDialog(msoFileDialogFilePicker)
If .Show Then
Rg = .SelectedItems(1)
End If
End With
End Function
文件是否存在的判断:
Public 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
文件夹是否存在的判断:
Public Function IsFdExists(ByVal FilePathStr As String) As Boolean
If Not Dir(FilePathStr, vbDirectory) = vbNullString Then
IsFdExists = True
Else
IsFdExists = False
End If
End Function
标签:Function,文件,vba,End,Rg,文件夹,objFileSystem,True,Public 来源: https://www.cnblogs.com/hellohellozxb/p/16396565.html