Thanks, Andrew.
There is a routine that you can use at
http://www.mvps.org/vbnet/code/fileapi/folderexists.htm
It is designed for VB rather than VBA, but it should work just fine if you
paste the relevant code in.
--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email
"Andrew Hancock" <and...@hancockhome.fsnet.co.uk> wrote in message
news:OXWWWsG7AHA.1340@tkmsftngp04...
Here's a demo. On a userform, put a textbox named tbFolderName, a label
named Label1, and two command buttons named btnCheckIt and btnQuit. Put this
code on the userform's code sheet:
Private Sub btnCheckIt_Click()
Dim fso As Object
If tbFolderName.Text = "" Then Exit Sub
On Error GoTo ErrHdl
' Need a FileSystemObject...
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(tbFolderName.Text) Then
Label1.Caption = "The folder already exists"
Else
' Try to create the folder. This may
' trigger the error handler.
MkDir tbFolderName.Text
Label1.Caption = "Created the folder"
End If
Exit Sub
ErrHdl:
Label1.Caption = Err.Description
End Sub
Private Sub btnQuit_Click()
Unload Me
End Sub
Regards,
Jay
Andrew Hancock <and...@hancockhome.fsnet.co.uk> wrote in message
news:OXWWWsG7AHA.1340@tkmsftngp04...
Mark
-- Mark Tangard <mtan...@speakeasy.net> ----------------------------
------ WWW: http://www.speakeasy.org/~mtangard ----------------------
------------- "Life is nothing if you aren't obsessed." --John Waters
---------------------------------------------------------------------
Yep, it uses WSH (Windows Scripting Host), probably from wscript.exe or
cscript.exe -- VBA doesn't tell you where it gets these things. And yes, WSH
is considered a security risk because the script kiddies are getting good at
hiding .vbs files as other file types and e-mailing them around the world,
so many folks disable the script engine. The alternative is the API version
that Jonathan pointed to.
Regards,
Jay
Mark Tangard <mtan...@speakeasy.net> wrote in message
news:3B1AECEB...@speakeasy.net...
Code for other users.
Private Sub btnCheckIt_Click()
Dim fso As Object
If tbFolderName.Text = "" Then Exit Sub
On Error GoTo ErrHdl
' Need a FileSystemObject...
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(tbFolderName.Text) Then
Label1.Caption = "The folder already exists"
Else
' Try to create the folder. This may
' trigger the error handler.
MkDir tbFolderName.Text
Label1.Caption = "Created the folder"
End If
Exit Sub
ErrHdl:
Label1.Caption = Err.Description
End Sub
Private Sub btnQuit_Click()
Unload Me
End Sub
Andrew Hancock <and...@hancockhome.fsnet.co.uk> wrote in message
news:OXWWWsG7AHA.1340@tkmsftngp04...