Hi Daxton!
From a forthcoming KB entry (in approval process right now)
Function FileOrDirExists(PathName As String) As Boolean
'Macro Purpose: Function returns TRUE if the specified file
' or directory exists, false if not.
'File usage : Provide full file path and extension
'Path usage : Provide full file path only (accepts with/without trailing "\")
Dim sTemp As String
'Ignore errors to allow for error evaluation
On Error Resume Next
sTemp = GetAttr(PathName)
'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
FileOrDirExists = True
Case Else
FileOrDirExists = False
End Select
'Resume error checking
On Error GoTo 0
End Function
So you could use it like so:
Sub TestIt()
'Macro Purpose: To test the FileOrDirExists function
'Only included to demonstrate the function. NOT required for normal use!
Dim sPath As String
'Change your directory here
sPath =
"S:\Daily Production Press Efficiency\" & "EFFICIENCY REPORTS " & _
NumYear & "\"
'Test if directory or file exists
If FileOrDirExists(sPath) Then
ActiveWorkbook.SaveAs FileName:= _
spath & NumMonth & "-" & Right(NumYear, 2) & _
" PRODUCTION EFFICIENCY REPORT.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Else
MsgBox sPath & " does not exist."
End If
End Sub
HTH,