ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GetSaveAs Method (https://www.excelbanter.com/excel-programming/310798-getsaveas-method.html)

M. Barnes

GetSaveAs Method
 
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.

Ron de Bruin

GetSaveAs Method
 
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" wrote in message ...
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.




Norman Jones

GetSaveAs Method
 
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

---
Regards,
Norman



"M. Barnes" wrote in message
...
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.




MB[_5_]

GetSaveAs Method
 
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" wrote

in message ...
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.



.


Ron de Bruin

GetSaveAs Method
 
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


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


"MB" wrote in message ...
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" wrote

in message ...
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.



.




Tom Ogilvy

GetSaveAs Method
 
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.

--
Regards,
Tom Ogilvy


"Ron de Bruin" wrote in message
...
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


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


"MB" wrote in message

...
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" wrote

in message ...
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.


.







All times are GMT +1. The time now is 03:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com