View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default checking for drive

I think you have all you need.

Option Explicit
Function DoesPathExist(myPath As String) As Boolean

Dim TestStr As String
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

TestStr = ""
On Error Resume Next
TestStr = Dir(myPath & "nul")
On Error GoTo 0

DoesPathExist = CBool(TestStr < "")

End Function

sub testme01()

dim myParentFolder as string
dim myFolder as string
myparentfolder = "U:\" 'something that I know exists
if doespathexist(myparentfolder) then
'keep going using U:
else
'switch to the C: drive
myparentfolder = "C:\"
end if

on error resume next
mkdir myparentfolder & "US 49"
mkdir myparentfolder & "US 49" & "\form 1257"
on error goto 0

myfolder = myparentfolder & "US 49" & "\form 1257"

'and use myfolder in the rest of your code.

end sub

========
untested, uncompiled--watch for typos.


jnf40 wrote:

Dave,

Ill try this again as far as explaining everything I am wanting to do, I
think I may be confusing myself more than anything, but here goes€¦

I want to check to see if drive €œU:€ is valid, if so then I want to check
for directory €œUS 49€, if it is there fine if not create it. If directory €œUS
49€ is there then I want to check for sub directory €œ1257 Forms€, if it is
there then my file would save there, if it is not there then it would create
the sub directory €œ1257 Forms€ then save my file there.
Now if drive €œU:€ is not a valid drive then it would check, create, and save
everything as above in drive €œC:€ So when all is finished I should have one
of the following paths:
€œU:\US 49\1257 Forms\my file€ if €œU:€ is a valid drive or
€œC:\US 49\1257 Forms\my file€ if drive €œU:€ is not a valid drive.

I have it now where it will do everything but check for and create the sub
directory. I hope I havent muddied the waters more, I appreciate your
patience and knowledge.


--

Dave Peterson