Microsoft Office Tutorials and References
In Depth Information
Some Useful Functions for Use in Your Code
The FileNameOnly function works with any path and filename (even if the file does not exist).
If the file exists, the following function is a simpler way to strip off the path and return only the
Private Function FileNameOnly2(pname) As String
FileNameOnly2 = Dir(pname)
End Function
The PathExists function
This function accepts one argument (a path) and returns True if the path exists:
Private Function PathExists(pname) As Boolean
‘ Returns TRUE if the path exists
If Dir(pname, vbDirectory) = “” Then
PathExists = False
PathExists = (GetAttr(pname) And vbDirectory) = vbDirectory
End If
End Function
The RangeNameExists function
This function accepts a single argument (a range name) and returns True if the range name
exists in the active workbook:
Private Function RangeNameExists(nname) As Boolean
‘ Returns TRUE if the range name exists
Dim 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
Search JabSto ::

Custom Search