PC Review


Reply
Thread Tools Rate Thread

How to determine if a Folder/Directory Exists in Excel VBA

 
 
robinson.william@gmail.com
Guest
Posts: n/a
 
      16th Nov 2006
Hi All,

Does anybody know how i can determine if a directory exists in VBA? For
example i would like to write a function that looks to see if the path
c:\reports\2006 exists, if so leave it be, if not create it.

Thanks,
Bill

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      16th Nov 2006
Why bother checking. Just ignore any errors that occur when you try to create
it:

on error resume next
mkdir "C:\reports"
mkdir "C:\reports\2006"
on error goto 0

(One level at a time.)

(E-Mail Removed) wrote:
>
> Hi All,
>
> Does anybody know how i can determine if a directory exists in VBA? For
> example i would like to write a function that looks to see if the path
> c:\reports\2006 exists, if so leave it be, if not create it.
>
> Thanks,
> Bill


--

Dave Peterson
 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      17th Nov 2006
Bill,
Dave's answer is native VBA, but there's also the API route:

<From API-Guide: URL: http://www.allapi.net/>
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll"
(ByVal lpPath As String) As Long

Private Sub Form_Load()
'create the directory "c:\this\is\a\test\directory\", if it doesn't exist
already
MakeSureDirectoryPathExists "c:\this\is\a\test\directory\"

End Sub
</From API-Guide:>

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi All,
>
> Does anybody know how i can determine if a directory exists in VBA? For
> example i would like to write a function that looks to see if the path
> c:\reports\2006 exists, if so leave it be, if not create it.
>
> Thanks,
> Bill
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How determine if directory exists windsurferLA Microsoft Excel Programming 6 3rd Nov 2007 06:14 PM
Need function to determine whether a directory exists Bob Valentine Microsoft Access VBA Modules 2 30th Jun 2007 06:39 PM
Determine if folder exists Terry K Microsoft Excel Programming 1 9th Jun 2006 06:26 PM
How to determine if directory exists TTD Microsoft Access VBA Modules 2 21st Jun 2005 01:05 PM
Re: How to determine if a MAPI folder exists? Sue Mosher [MVP-Outlook] Microsoft Outlook VBA Programming 0 27th Sep 2004 05:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:50 PM.