Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error Message

The Dir() can cause a runtime error if the drive drive doesn't exist.

Using "On error resume next" to ignore the error that you know might occur seems
like a reasonable approach to me.

Option Explicit
Sub testme()
Dim ok As Boolean
Call FolderExistCheck("\\a\asfd", ok)
MsgBox ok
End Sub
Sub FolderExistCheck(strFullPath As String, Exists As Boolean)

Dim myStr As String

Exists = False

If strFullPath = "" Then
'do nothing
Else
myStr = ""
On Error Resume Next
myStr = Dir(strFullPath, vbDirectory)
On Error GoTo 0
If myStr < "" Then
Exists = True
End If
End If

End Sub





Jeff wrote:

Hi,

I have code that checks if a folder exists

strFullPath = "D:\Release"

Sub FolderExistCheck(strFullPath As String, Exists As Boolean)
'if Exists = True then the path exists
If Not Dir(strFullPath, vbDirectory) = vbNullString Then Exists = True
If strFullPath = "" Then Exists = False
End Sub

"D:\Release" does not exist but instead of returning "False" it returns
Bad filename or number. But this only happens with the D: directory if the
directory starts with C: it returns false. Does anyone know why this is?

Thanks


--

Dave Peterson
 
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
IF(AND) error message mr_concrete Excel Worksheet Functions 5 February 6th 07 08:11 PM
VBA Error Message "Compile Error...." Steve Excel Discussion (Misc queries) 3 July 15th 05 09:20 AM
changing the message in an error message The Villages DA Excel Worksheet Functions 2 February 18th 05 05:30 PM
How do I get rid of "Compile error in hidden module" error message David Excel Discussion (Misc queries) 4 January 21st 05 11:39 PM
#num! error message Brenda Excel Worksheet Functions 4 November 19th 04 03:55 AM


All times are GMT +1. The time now is 12:37 AM.

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

About Us

"It's about Microsoft Excel"