Create new folder macro

Erick

Active Member
Joined
Feb 26, 2003
Messages
360
Hi, I need to write a vb code to save workbook. I am using today's date as the folder name where i want it saved in. How do I write a vb code so that if, say the folder '17-Oct-06' already exist, then save it in there but if doesn't then create a new folder and then save.
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491
Code:
Sub Check_Folder()
MyFolder = "c:\" & Format(Date, "dd-mmm-yy")
If Dir(MyFolder, vbDirectory) = "" Then
    MkDir MyFolder
End If
'adjust the filename to your needs...
ActiveWorkbook.SaveAs FileName:=MyFolder & "\" & Format(Date, "dd-mmm-yy")
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,111,910
Messages
5,541,538
Members
410,547
Latest member
htran4
Top