Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Path Not Found

I am trying to determine the presence of a file using the
DIR command as follows:

If Len(Dir(path & wbook)0 Then
'File Found
End If

However, when the path variable is not available, my
macro aborts with the error message "Path not Found".

I'd appreciate any suggestions on how I can determine the
path is not present before I get the error message.

Thanks for any suggestions.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Path Not Found

I just turn off the error checking and check to see if I found what I wanted.

Option Explicit
Sub testme()

Dim myPath As String
Dim wBook As String
Dim testStr As String

myPath = "\\myserver\mypath\excel\"
wBook = "book1.xls"
testStr = ""
On Error Resume Next
testStr = Dir(myPath & wBook)
On Error GoTo 0

If testStr = "" Then
MsgBox "filename not found--or folder/drive not found"
End If

End Sub



Michael wrote:

I am trying to determine the presence of a file using the
DIR command as follows:

If Len(Dir(path & wbook)0 Then
'File Found
End If

However, when the path variable is not available, my
macro aborts with the error message "Path not Found".

I'd appreciate any suggestions on how I can determine the
path is not present before I get the error message.

Thanks for any suggestions.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Path Not Found


CheckPath: 'the next few lines of code will check to see if th
directory exists

With Application.FileSearch
.LookIn = ThisPath
If .LookIn < ThisPath Then
'if the directory does not exist, we will print
'an error message
MsgBox "Could not find the directory"
Else:
GoTo LookForFiles
End If
End With

LookForFiles:
'the next few lines of code will ensure that the file exists in tha
directory

With Application.FileSearch
.LookIn = ThisPath 'directory path
.Filename = "*.xls"
.SearchSubFolders = False

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If FileYouWant = .FoundFiles(i) Then GoTo StartWork
Next i
Else
MsgBox "There were no files found in " & ThisFilePath
vbCritical
GoTo EndOfMacro
End If
NumberOfFilesFound = .FoundFiles.Count
End Wit

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

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
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 AM
Path Not Found Error Ric Payne Excel Programming 0 October 29th 03 07:59 AM
Which Path not found? Tod Excel Programming 3 August 2nd 03 02:03 PM


All times are GMT +1. The time now is 01:46 AM.

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"