Write a function to verify an Excel file is exists, if not create it.



Option Explicit
Dim fileSysObj,msExcelObj,msWorkBook
Dim msWorkSht

Function fileExist(filePath)

Set fileSysObj=CreateObject("Scripting.FileSystemObject")
fileExist=fileSysObj.FileExists(filePath)
If fileExist=True Then
                             msgbox "File is exists"
                             Set fileSysObj=Nothing
Else
                             Set msExcelObj=CreateObject("Excel.Application")
                             Set msWorkBook=msExcelObj.WorkBooks.Add
                             Set msWorkSht=msWorkBook.WorkSheets("Sheet1")
                             msWorkBook.SaveAs filePath
                             Set msWorkSht=Nothing
                             Set msWorkSht=Nothing
                             Set msExcelObj=Nothing
End If

End Function

Call fileExist("D:\sample1.xls")

m.vamsigowtham@gmail.com 
Contributed by: Vamshi Gowtham