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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,171,163
Messages
5,874,125
Members
433,026
Latest member
LawnmowerITGuy

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
Top