Noticias:

Ya hay algunas cosas colgadas en la web así que ya vuelve a estar disponible.

Menú Principal

Saber si un fichero existe

Iniciado por xavi, Abril 21, 2020, 05:05:29 PM

Tema anterior - Siguiente tema

xavi

Palabras clave: FSO, averiguar, saber, archivo, fichero
Autor: Xavi
Extraído de: Centro de desarrollo de Office



Objetivo
Averiguar si un fichero existe mediante FSO. Es la alternativa a Dir(strFileName, vbArchive) que puede dar errores cuando strFileName = ""


Public Function ExistsFile(strFileName As String) As Boolean
    Dim fso As Object
   
    Set fso = CreateObject("Scripting.FileSystemObject")
   
    On Error Resume Next
    If fso.FileExists(strFileName) = False Then
        ExistsFile = False
    Else
        ExistsFile = True
    End If
   
    If Err <> 0 Then
        ExistsFile = False
    End If
   
    Set fso = Nothing
       
End Function