How to: check if folder exist, if not, create

E

escorido

Hello to all,

How to check if the folder exist in the ActiveWorkbook.Path directory
if it doesn't, create the folder there?

Could anyone show some sample codes on how to do this?
I'm still new to ExcelVBA and not familiar with it.

Thanks a lot
 
A

AA2e72E

The code is:

Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long

Sub CreateFolder()
MakeSureDirectoryPathExists Application.DefaultFilePath & "\YOURFOLDER\"
End Sub

where \YOURFOLDER\ is the name of the folder whose existence you want to ensure: note trailing \.
 
T

Tom Ogilvy

On error resume next
mkdir ActiveWorkbook.Path & "\myfolder"
On Error goto 0
 
Top