I want to test a path before using my code. like if it is wrong i can show a userform for checking a new path
but i don't see, is there a function for this ?
Printable View
I want to test a path before using my code. like if it is wrong i can show a userform for checking a new path
but i don't see, is there a function for this ?
Can't you just use Error Trapping in the routine that finds the file?
I don't know the exact code but here's the idea:
i.e.
Code:Public Function IsFile(byVal strPath as String) As Boolean
On Error Goto Err_IsFile
check if the file exists
IsFile = True
Exit_IsFile:
Exit Function
Err_IsFile:
IsFile = False
Resume Exit_IsFile
End Function
and then, before you run the code to open your file or whatever, something like this
Code:If IsFile(strYourFileName) Then
' open file
Else
MsgBox "Not a valid file."
End If
ok thanks a lotyour code work, but i simplified it a little
Sub test()
Dim mypath As String
On Error GoTo ifmyfileiswrong
Workbooks.Open filename:=Range("J2").Value
' my stuff if no error
ifmyfileiswrong:
' my stuff if error
End Sub
thanks a lot
:D