ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to check if a folder/directory exist using VBA (https://www.excelbanter.com/excel-programming/293003-how-check-if-folder-directory-exist-using-vba.html)

wellie

How to check if a folder/directory exist using VBA
 
Can someone please tell me how can I check if a
directory/folder already exist using VBA within Excel ?

I tried the followings and it did not work

if Len(Dir("c:\mypath\myfolder")) = 0 then
mkdir("c:\mypath\myfolder\newfolder")
else
msgbox "Folder 'myfolder' already exist."

endif

Regards

Tom Ogilvy

How to check if a folder/directory exist using VBA
 
You can skip the test

On Error Resume Next
mkdir("c:\mypath\myfolder\newfolder")
On Error goto 0

this assumes mypath and mypath\myfolder exist.

If not, you can use the same principle


On Error Resume Next
mkdir("C:\mypath")
mkdir("C:\mypath\myfolder")
mkdir("c:\mypath\myfolder\newfolder")
On Error goto 0

--
Regards,
Tom Ogilvy


"wellie" wrote in message
...
Can someone please tell me how can I check if a
directory/folder already exist using VBA within Excel ?

I tried the followings and it did not work

if Len(Dir("c:\mypath\myfolder")) = 0 then
mkdir("c:\mypath\myfolder\newfolder")
else
msgbox "Folder 'myfolder' already exist."

endif

Regards





All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com