View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Don't understand results of UDF

This line:
x = Dir(PathName & "\*.*")


instructs the UDF to search for

C:\Documents and Settings\XlsFileSavedAsText.txt\*.*

Since xlsFileSavedAsText.txt is a file, not a folder with files in it - it
returns false. You could remove the & "\*.*" or try:


Private Function udfFileExists(strFileName As String) As Boolean
udfFileExists =
CreateObject("Scripting.FileSystemObject").FileExi sts(strFileName)
End Function






"JMay" wrote:

In cell B4 I have (as text):

C:\Documents and Settings\XlsFileSavedAsText.txt

In Cell C2 I have:

=PathExists(B4)

In my Module1 I have:

Private Function PathExists(PathName As String) As Boolean
' Returns True If PathExists
On Error GoTo NoPath
x = Dir(PathName & "\*.*")
If x = "" Then GoTo NoPath
PathExists = True
Exit Function
NoPath:
PathExists = False
End Function

Why is my Cell C2 showing False
when I definitely
C:\Documents and Settings\XlsFileSavedAsText.txt Exists?

TIA,

Jim