GetSaveAs Method

  • Thread starter Thread starter M. Barnes
  • Start date Start date
M

M. Barnes

Is there a way to create the folder if the suggested path
does not exist? In other words, search for the suggested
folder first, if it doesn't exist, the system will
prompt "That folder does not exist, do you wish to create
it?".

I've seen this happen in other programs, and desire to
add it to mine. I'm currently using the GetSaveAs
method, but am not sure if it is the best way.

Thanks for any help you can provide.
 
Try this

Sub MakeDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\MyDir"
If Not fs.FolderExists(Dirname) Then
fs.CreateFolder Dirname
Else
' do nothing
End If
End Sub
 
Hi M,

The following will create the new folder if it does not exist and will not
complain if it does :

On Error Resume Next
MkDir "C:\MyNewFolder"
On Error GoTo 0
 
This is okay, but I want user input to confirm the new
directory name.
-----Original Message-----
Try this

Sub MakeDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\MyDir"
If Not fs.FolderExists(Dirname) Then
fs.CreateFolder Dirname
Else
' do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"M. Barnes" <[email protected]> wrote
in message news:[email protected]...
 
Try this

Sub MakeDirectory2()
Dim Dirname As String
Dim Answer As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\MyDir"
If Not fs.FolderExists(Dirname) Then
Answer = MsgBox("Do you want to create a folder", vbOKCancel)
If Answer = vbOK Then
fs.CreateFolder Dirname
Else
'nothing
End If
Else
' do nothing
End If
End Sub
 
Just a heads up:
This will fail unless the lowest folder is the only one missing. You might
want to add code to protect for that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top