View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default verify a path exists

Here are two functions I use all the time, as alternatives to Dir. I got
them from VB6 MVP Karl Peterson.

''================================================ ============================

Function FileExists(ByVal FileSpec As String) As Boolean

' Karl Peterson MS VB MVP

Dim Attr As Long

' Guard against bad FileSpec by ignoring errors

' retrieving its attributes.

On Error Resume Next

Attr = GetAttr(FileSpec)

If Err.Number = 0 Then

' No error, so something was found.

' If Directory attribute set, then not a file.

FileExists = Not ((Attr And vbDirectory) = vbDirectory)

Else

m_ErrorText = Err.Description

End If

End Function

''================================================ ============================

Function DirExists(ByVal FileSpec As String) As Boolean

' Karl Peterson MS VB MVP

Dim Attr As Long

' Guard against bad FileSpec by ignoring errors

' retrieving its attributes.

On Error Resume Next

Attr = GetAttr(FileSpec)

If Err.Number = 0 Then

' No error, so something was found.

' If Directory attribute set, then not a file.

DirExists = (Attr And vbDirectory) = vbDirectory

Else

m_ErrorText = Err.Description

End If

End Function

''================================================ ============================


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"JLGWhiz" wrote in message
...
This is probably so simple that I am overlooking it. I want to write code
as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.