Create a folder

TeacherEric

Board Regular
Joined
Mar 21, 2006
Messages
78
Hi,

I have found a way to create a folder then to save my file to that folder. However, if the folder already exists I get an error.

Can someone show me how create a code that will:

1) Check to see if a folder is there already.
2) If the folder is there - ignore the create and just save it
3) If the folder isn't there - create it – save it.

My folder will always be called the same thing "C:\Gradebooks"

My filename will be based off a cell reference:
sheets("information").range("K151")

Thank you very much.
TeacherEric
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this.
Code:
Sub CreateFldr()
    
    If Dir("C:\Gradebooks", vbDirectory) = "" Then
        MkDir "C:\Gradebooks"
        MsgBox "Folder created."
    Else
        MsgBox "Folder exists."
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top