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

  • Thread starter Thread starter escorido
  • Start date Start date
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
 
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 \.
 
On error resume next
mkdir ActiveWorkbook.Path & "\myfolder"
On Error goto 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top