Private Function FileExists(fname) As Boolean' Returns TRUE if the file existsDim x As Stringx = Dir(fname)If x <> "" Then FileExists = True _Else FileExists = FalseEnd Function
The FileNameOnly Function
Private Function FileNameOnly(pname) As String' Returns the filename from a path/filename stringDim i As Integer, length As Integer, temp As String length = Len(pname) temp = "" For i = length To 1 Step -1 If Mid(pname, i, 1) = Application.PathSeparator Then FileNameOnly = temp Exit Function End If temp = Mid(pname, i, 1) & temp Next i FileNameOnly = pname End Function
The PathExists Function
Private Function PathExists(pname) As Boolean' Returns TRUE if the path existsDim x As String On Error Resume Next x = GetAttr(pname) And 0 If Err = 0 Then PathExists = True Else PathExists = False End Function
The RangeNameExists Function
Private Function RangeNameExists(nname) As Boolean' Returns TRUE if the range name existsDim n As Name RangeNameExists = False For Each n In ActiveWorkbook.Names If UCase(n.Name) = UCase(nname) Then RangeNameExists = True Exit Function End If Next n End Function
The SheetExists Function
Private Function SheetExists(sname) As Boolean' Returns TRUE if sheet exists in the active workbookDim x As Object On Error Resume Next Set x = ActiveWorkbook.Sheets(sname) If Err = 0 Then SheetExists = True Else SheetExists = False End Function
No comments:
Post a Comment