Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

FileSystemObject : FileExists Method

Description: 

Returns True if a spec­i­fied file exists; False if it does not.

Format : 

objectOf­FileSys­te­mOb­ject. FolderExists(fileName)

objectOf­FileSys­te­mOb­ject : As the names says, it’s a FileSystemObject.

Arguments: 
    • file­Name
      • Manda­tory
      • Type:     String
      • File , whose exis­tence to be determined.

Function FnIsFileExist(strCompleteFilePath)
      Set fso = CreateObject("Scripting.FileSystemObject")
      If fso. FileExists(strCompleteFilePath)Then
                    strStatus = strCompleteFilePath & “  file exists”
            Else
                    strStatus = strCompleteFilePath & “  file does not exist”
           End If
        FnIsFolderExist = strStatus
End Function

Msg­box FnIs­File­Ex­ist (“c:\New Folder\file.txt”)

 

You may also like...

2 Responses

  1. Vishal Tulsiyan says:

    Hav­ing a hard time exe­cut­ing these( just a begin­ner #embarrassed).

    By default, in my code win­dow i had some code written[in a new work­book]. i deleted them and wrote this code:
    Func­tion FnIsFileExits(strCompleteFilePath)
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    If fso.FileExits(strCompleteFilePath) Then
    strSta­tus = str­Com­plete­FilePath & “File there nigga“
    Else
    strSta­tus = str­Com­plete­FilePath & “Aint no FIle there man”

    FnIs­FolderEx­ists = strSta­tus
    End Function

    How­ever, i was not sure where to run/call this func­tion from. i clicked on what looked like a play but­ton and it asked me to save my micro. so i did with name: FnIs­File­Ex­its.
    This took me to another[new code] win­dow where below code was there by default:

    Sub isFile­Ex­ists()

    End Sub

    i had no idea what to do next. so i wrote this inside[stupid enough i know]:

    Sub isFile­Ex­ists()
    Msg­Box FnIsFileExits(“D:/hello.xmls”)
    End Sub

    when i tried to run this i got below error:

    —————————
    Microsoft Visual Basic for Appli­ca­tions
    —————————
    Com­pile error:

    Sub or Func­tion not defined
    —————————
    OK Help
    —————————

    i would be really help­ful if you can show full cod­ing of the pro­gram or a how to run thingy.

    • sumitjain says:

      there were very small mis­takes ..
      below is the code which worked for me

      Sub Vishal()

      Msg­Box FnIsFileExits(“D:/hello.xmls”)

      End Sub

      Func­tion FnIsFileExits(strCompleteFilePath)
      Set fso = CreateObject(“Scripting.FileSystemObject”)
      If fso.FileExists(strCompleteFilePath) Then
      strSta­tus = str­Com­plete­FilePath & “File there nigga“
      Else
      strSta­tus = str­Com­plete­FilePath & “Aint no FIle there man“
      End If

      FnIs­File­Ex­its = strSta­tus
      End Function

      IF you wanna read more about File Sys­tem objects, here is the link
      http://excel-macro.tutorialhorizon.com/filesystemobject-in-excel-macro/

      Feel free to ask anythg 🙂

      Sumit

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: