ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Creating a new folder that does not already exsit. (https://www.excelbanter.com/excel-discussion-misc-queries/150441-creating-new-folder-does-not-already-exsit.html)

Ryan

Creating a new folder that does not already exsit.
 
I don't know what it is, I have tried multiple variations of this code and
still cannot get it to function.

Sub SaveAndClose1()
Path = "C:\Forms\F-50"
If Dir(Path, vbDirectory) = vbNullString Then
MkDir "C:\Forms\F-50"
End If
ActiveWorkbook.SaveAs Filename:="C:\Forms\F-50\" & Range("C6").Value &
Format(Date, "ddmmmyyyy") & ".xls"
'ActiveWorkbook.Close
End Sub

Attempting to to have a button that upon clicking will save the workbook to
C:\Forms\F-50. No computer that this will be used on will have this folders.
So they need to be created but if they have already done so, i want it just
to save there. Like I said I've used a lot of different variations and still
no go. Please Advise.

Your lovable stressed out intern.

Dave Peterson

Creating a new folder that does not already exsit.
 
I'd use:

on error resume next
mkdir "C:\forms"
mddir "c:\forms\f-50"
on error goto 0

activeworkbook.saveas ....

As long as the user has permission and there aren't any files with those names,
it should work ok.

(If either or both of the folders exist, then the "on error resume next" will
suppress any message.)

Ryan wrote:

I don't know what it is, I have tried multiple variations of this code and
still cannot get it to function.

Sub SaveAndClose1()
Path = "C:\Forms\F-50"
If Dir(Path, vbDirectory) = vbNullString Then
MkDir "C:\Forms\F-50"
End If
ActiveWorkbook.SaveAs Filename:="C:\Forms\F-50\" & Range("C6").Value &
Format(Date, "ddmmmyyyy") & ".xls"
'ActiveWorkbook.Close
End Sub

Attempting to to have a button that upon clicking will save the workbook to
C:\Forms\F-50. No computer that this will be used on will have this folders.
So they need to be created but if they have already done so, i want it just
to save there. Like I said I've used a lot of different variations and still
no go. Please Advise.

Your lovable stressed out intern.


--

Dave Peterson

Bob Phillips

Creating a new folder that does not already exsit.
 
Sub SaveAndClose1()
On Error Resume Next
MkDir "C:\Forms"
MkDir "C:\Forms\F-50"
On Error Goto 0
ActiveWorkbook.SaveAs Filename:= _
"C:\Forms\F-50\" & Range("C6").Value & Format(Date, "ddmmmyyyy") &
".xls"
'ActiveWorkbook.Close
End Sub



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Ryan" wrote in message
...
I don't know what it is, I have tried multiple variations of this code and
still cannot get it to function.

Sub SaveAndClose1()
Path = "C:\Forms\F-50"
If Dir(Path, vbDirectory) = vbNullString Then
MkDir "C:\Forms\F-50"
End If
ActiveWorkbook.SaveAs Filename:="C:\Forms\F-50\" & Range("C6").Value &
Format(Date, "ddmmmyyyy") & ".xls"
'ActiveWorkbook.Close
End Sub

Attempting to to have a button that upon clicking will save the workbook
to
C:\Forms\F-50. No computer that this will be used on will have this
folders.
So they need to be created but if they have already done so, i want it
just
to save there. Like I said I've used a lot of different variations and
still
no go. Please Advise.

Your lovable stressed out intern.




Ryan

Creating a new folder that does not already exsit.
 
THank you Bob and Dave, you guys are a lot of help. That did the trick. I'll
remember the On Error part next time, I completely forgot about that.

"Bob Phillips" wrote:

Sub SaveAndClose1()
On Error Resume Next
MkDir "C:\Forms"
MkDir "C:\Forms\F-50"
On Error Goto 0
ActiveWorkbook.SaveAs Filename:= _
"C:\Forms\F-50\" & Range("C6").Value & Format(Date, "ddmmmyyyy") &
".xls"
'ActiveWorkbook.Close
End Sub



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Ryan" wrote in message
...
I don't know what it is, I have tried multiple variations of this code and
still cannot get it to function.

Sub SaveAndClose1()
Path = "C:\Forms\F-50"
If Dir(Path, vbDirectory) = vbNullString Then
MkDir "C:\Forms\F-50"
End If
ActiveWorkbook.SaveAs Filename:="C:\Forms\F-50\" & Range("C6").Value &
Format(Date, "ddmmmyyyy") & ".xls"
'ActiveWorkbook.Close
End Sub

Attempting to to have a button that upon clicking will save the workbook
to
C:\Forms\F-50. No computer that this will be used on will have this
folders.
So they need to be created but if they have already done so, i want it
just
to save there. Like I said I've used a lot of different variations and
still
no go. Please Advise.

Your lovable stressed out intern.






All times are GMT +1. The time now is 02:04 AM.

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