![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Houston,Texas
Posts: 418
|
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 ] |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 7
|
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 |
|
|
|
|
|
#4 |
|
New Member
Join Date: Feb 2002
Posts: 10
|
Thanks Guys
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|