Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save file to same directory folder RobN[_2_] Excel Discussion (Misc queries) 2 April 4th 10 08:06 AM
hyperlink to directory folder while highlighting filename locojester Links and Linking in Excel 1 February 10th 10 08:27 AM
hyperlink to directory folder while highlighting filename locojester Excel Discussion (Misc queries) 0 February 10th 10 12:01 AM
Check for a tab if it is exist Farhad Excel Discussion (Misc queries) 2 December 21st 08 07:31 PM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM


All times are GMT +1. The time now is 01:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"