Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Verify before proceeding | Excel Programming | |||
hyperlink navigation path path wrong in Excel 2003 | Excel Discussion (Misc queries) | |||
how to change absolute path to relative path | Excel Worksheet Functions | |||
Verify email | Excel Discussion (Misc queries) | |||
Verify a directory exists | Excel Programming |