Thursday, July 3, 2008

Check if a File Exists

Here is a quick script to check if a file exists.

Sub TestForFileSubroutine() 

   ‘Create a File System Object 
  Set objFSO = CreateObject("Scripting.FileSystemObject")

   ‘Set a variable that points to the File
   cFilePathAndName = “c:\TEMP\MyFileName.TXT”

   ‘Does the file exist?
   If Not objFSO.FileExists(cFilePathAndName) Then
       MsgBox "FILE DOES NOT EXIST!"
       Exit Sub
   End If
 
   ‘Do a little clean up and delete the File System Object
   Set objFSO = Nothing

End Sub

No comments:

Time Math in Excel

You can use the TIME() function to add or subtract hours, minutes or seconds in Excel.  The TIME function takes 3 parameters; HOURS, MINUTES...