Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Don't understand results of UDF

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Don't understand results of UDF

Because

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

definitely DOESN'T exist.

Your UDF is looking for a Path, not the entire filename.

If you remove the "\XlsFileSavedAsText.txt" from B3, then PathExists
will return TRUE.



In article , "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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Don't understand results of UDF


Or remove:
& "\*.*"
To give you:
X = Dir(PathName)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"JMay"
wrote in message
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Don't understand results of UDF

JE - Thanks for clearing up my confusion. Obviously,
the Code searches at the Folder level ONLY;
It was the reference in the code *.* that confused me.
This should never happen again. LOL
Tks,
Jim

"JE McGimpsey" wrote in message
:

Because

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

definitely DOESN'T exist.

Your UDF is looking for a Path, not the entire filename.

If you remove the "\XlsFileSavedAsText.txt" from B3, then PathExists
will return TRUE.



In article , "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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Don't understand results of UDF

Thanks Jim,
Yes, that's what I decided I needed to do,
based on JE's comment. Thanks for "nailing-it"!!
JMay

"Jim Cone" wrote in message
:

Or remove:
& "\*.*"
To give you:
X = Dir(PathName)
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"JMay"
wrote in message
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Don't understand results of UDF

Are you looking to see if the path exists or the file itself exists? (You
parameter name is confusing as you are passing the full flilename not just
the path) If you want to check that the file exists then uses this syntax

x = dir(Pathname)

if you want to check if the path exists then

x = dir(left(pathname, instrrev(pathname,"\")) & "*.*")
(ideally replace "\" with application.pathseparator to allow for different
filesystems)

what you have coded means "does C:\Documents and
Settings\XlsFileSavedAsText.txt\*.* exist?", to which the answer is no.

hope this helps,
D

"JMay" wrote in message
...
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



  #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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gap or something I cannot understand MFS Excel Discussion (Misc queries) 1 August 26th 09 12:13 AM
not understand [email protected] New Users to Excel 1 February 24th 08 02:18 PM
I don't Understand elusiverunner Excel Worksheet Functions 6 November 25th 05 09:19 PM
Help me understand this code Carrot Excel Discussion (Misc queries) 2 October 14th 05 06:07 AM
<> Scooterdog Excel Worksheet Functions 1 November 8th 04 07:56 AM


All times are GMT +1. The time now is 08:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"