Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Check the path for validity

Good morning,

I have cells C5:C10 (merged cells) in my worksheet "Sheet1" where users can
type in a path, including the file name (e.g. "C:\File.xls"), that users want
to save the workbook.

I need some help to write a code to validate the path to make sure that the
path is correct. If the path is not correct, I want to message the users
that the path you have entered is not a correct path format.

This code will be part of if - then statement of my other code.

Please help.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Check the path for validity

Dim strFile as String
strFile = Trim(Range("C5"))

If Dir(Left(strFile, InStrRev(strFile, "\")), vbDirectory) = "" Then
MsgBox "Invalid Path"
End If

PS: Alternatively you can also use FSO FileSystemObject to validate...

If this post helps click Yes
---------------
Jacob Skaria


"Souny" wrote:

Good morning,

I have cells C5:C10 (merged cells) in my worksheet "Sheet1" where users can
type in a path, including the file name (e.g. "C:\File.xls"), that users want
to save the workbook.

I need some help to write a code to validate the path to make sure that the
path is correct. If the path is not correct, I want to message the users
that the path you have entered is not a correct path format.

This code will be part of if - then statement of my other code.

Please help.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Check the path for validity

Using FSO..

Dim strFile As String, fso As Object
strFile = Trim(Range("C5"))

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(Left(strFile, InStrRev(strFile, "\") - 1)) Then
MsgBox "Folder exists"
End If

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Dim strFile as String
strFile = Trim(Range("C5"))

If Dir(Left(strFile, InStrRev(strFile, "\")), vbDirectory) = "" Then
MsgBox "Invalid Path"
End If

PS: Alternatively you can also use FSO FileSystemObject to validate...

If this post helps click Yes
---------------
Jacob Skaria


"Souny" wrote:

Good morning,

I have cells C5:C10 (merged cells) in my worksheet "Sheet1" where users can
type in a path, including the file name (e.g. "C:\File.xls"), that users want
to save the workbook.

I need some help to write a code to validate the path to make sure that the
path is correct. If the path is not correct, I want to message the users
that the path you have entered is not a correct path format.

This code will be part of if - then statement of my other code.

Please help.

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,722
Default Check the path for validity

Modify to suit:

Sub test()

'Establish file name somehow
MyPath = "C:\Documents and Settings\My Documents\My Book.xls"

'Checks for validity
Check = Dir(MyPath)
If Check = "" Then
MsgBox "Invalid file name"
End If
'Rest of your code
'would then go here

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Souny" wrote:

Good morning,

I have cells C5:C10 (merged cells) in my worksheet "Sheet1" where users can
type in a path, including the file name (e.g. "C:\File.xls"), that users want
to save the workbook.

I need some help to write a code to validate the path to make sure that the
path is correct. If the path is not correct, I want to message the users
that the path you have entered is not a correct path format.

This code will be part of if - then statement of my other code.

Please help.

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Check the path for validity

the good ol' DIR() still lives. With it, you get the file name or nothing ...

Option Explicit
Sub test()
MsgBox ValidPath("C:\Temp\LOG_SSG1_2009-09-09.log")
End Sub
Function ValidPath(spath As String) As Boolean
Dim sname As String
sname = Dir(spath)
ValidPath = sname < ""
End Function

"Souny" wrote:

Good morning,

I have cells C5:C10 (merged cells) in my worksheet "Sheet1" where users can
type in a path, including the file name (e.g. "C:\File.xls"), that users want
to save the workbook.

I need some help to write a code to validate the path to make sure that the
path is correct. If the path is not correct, I want to message the users
that the path you have entered is not a correct path format.

This code will be part of if - then statement of my other code.

Please help.

Thanks.



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
File Path Too Long? Not Anymore! Check out Long Path Tool Max Loger Excel Discussion (Misc queries) 1 March 24th 17 07:59 AM
How can I show a validity by a prompted symbol in colour? Maray Excel Worksheet Functions 1 February 3rd 09 10:47 AM
Check path and files jnf40 Excel Programming 4 November 27th 07 11:52 PM
=VLOOKUP validity Greg H Excel Programming 3 January 22nd 07 12:38 PM
Recordset object loses validity in call between function & subrout Dick Kusleika[_3_] Excel Programming 1 August 13th 04 08:22 AM


All times are GMT +1. The time now is 09:51 PM.

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"