Checking a file path

bobeuk

New Member
Joined
Feb 18, 2002
Messages
10
How can I check that a file path is correct? I am getting the user to enter the path in a cell (to be used by various other macros). I then want to perform a validation on that to check that the path exists.

Thanks

John
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Here's a piece of code from a macro I use:

Dim Path As String
Path = "C:Documents and SettingsSHartmanMy DocumentsRata" & Year(Date)
' Check if directory for this year exists
If Dir(Path, vbDirectory) = "" Then
'If not, make it
MkDir "C:Documents and SettingsSHartmanMy DocumentsRata" & Year(Date)
End If

Of course the double slashes should be single slashes.Hope this gets you started
This message was edited by Steve Hartman on 2002-02-28 05:10
This message was edited by Steve Hartman on 2002-02-28 05:39
This message was edited by Steve Hartman on 2002-02-28 05:41
 
Upvote 0
I use this function that works very well:

If PathExists(cell) = False Then
MsgBox cell & " does not exist.", vbOKOnly, "File Path Error."

End If


Public Function PathExists(pname) As Boolean
'Returns true if the path exists
Dim y As String
On Error Resume Next
x = GetAttr(pname) And 0
If Err = 0 Then
PathExists = True
Else: PathExists = False
End If
End Function
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top