Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default verify a path exists

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default verify a path exists

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default verify a path exists

Thanks Dave, I knew it was not that hard, but my 71 year old brain don't
function too well sometimes.

"Dave Peterson" wrote:

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default verify a path exists

Man, I hope you're not 80.

The first 9 years would have been tough!

JLGWhiz wrote:

Thanks Dave, I knew it was not that hard, but my 71 year old brain don't
function too well sometimes.

"Dave Peterson" wrote:

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default verify a path exists

Nope just 71 in Oct. I used the Dir() function but I found that the back
slash and a file name are required to make it work right.

exmpl: teststr = Dir("C:\Windows\Media\*.mid") . This gives me specific
info to make the program run right.

Thanks again.

"Dave Peterson" wrote:

Man, I hope you're not 80.

The first 9 years would have been tough!

JLGWhiz wrote:

Thanks Dave, I knew it was not that hard, but my 71 year old brain don't
function too well sometimes.

"Dave Peterson" wrote:

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default verify a path exists

That will return something if there is a file with the extension of .mid.

But it's really not a good check to see if a folder exists (just to stress a
very minor point).



JLGWhiz wrote:

Nope just 71 in Oct. I used the Dir() function but I found that the back
slash and a file name are required to make it work right.

exmpl: teststr = Dir("C:\Windows\Media\*.mid") . This gives me specific
info to make the program run right.

Thanks again.

"Dave Peterson" wrote:

Man, I hope you're not 80.

The first 9 years would have been tough!

JLGWhiz wrote:

Thanks Dave, I knew it was not that hard, but my 71 year old brain don't
function too well sometimes.

"Dave Peterson" wrote:

I do this:

Dim TestStr as string

teststr = ""
on error resume next
teststr = dir("c:\windows\media\nul")
on error goto 0

if teststr = "" then
'doesn't exist
else
'it's there
end if

====
But this'll work, too:

If CreateObject("Scripting.FileSystemobject") _
.folderexists("C:\windows\media") = True Then
MsgBox "Yep"
Else
MsgBox "nope"
End If

JLGWhiz wrote:

This is probably so simple that I am overlooking it. I want to write code as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. Thanks.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default verify a path exists

Here are two functions I use all the time, as alternatives to Dir. I got
them from VB6 MVP Karl Peterson.

''================================================ ============================

Function FileExists(ByVal FileSpec As String) As Boolean

' Karl Peterson MS VB MVP

Dim Attr As Long

' Guard against bad FileSpec by ignoring errors

' retrieving its attributes.

On Error Resume Next

Attr = GetAttr(FileSpec)

If Err.Number = 0 Then

' No error, so something was found.

' If Directory attribute set, then not a file.

FileExists = Not ((Attr And vbDirectory) = vbDirectory)

Else

m_ErrorText = Err.Description

End If

End Function

''================================================ ============================

Function DirExists(ByVal FileSpec As String) As Boolean

' Karl Peterson MS VB MVP

Dim Attr As Long

' Guard against bad FileSpec by ignoring errors

' retrieving its attributes.

On Error Resume Next

Attr = GetAttr(FileSpec)

If Err.Number = 0 Then

' No error, so something was found.

' If Directory attribute set, then not a file.

DirExists = (Attr And vbDirectory) = vbDirectory

Else

m_ErrorText = Err.Description

End If

End Function

''================================================ ============================


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"JLGWhiz" wrote in message
...
This is probably so simple that I am overlooking it. I want to write code
as
an If...Then method to verify that a certain path exists. Let's say
"C:\Windows|Media".
I tried the Exists( What ) method but could not find an object that VBA
liked. Make me feel stupid and show me the code. 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
Verify before proceeding snowing[_5_] Excel Programming 7 June 6th 06 01:49 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 AM
Verify email Sandee Excel Discussion (Misc queries) 1 February 9th 05 04:01 PM
Verify a directory exists MacroMan[_4_] Excel Programming 3 August 8th 03 04:38 PM


All times are GMT +1. The time now is 04:41 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"