PC Review


Reply
Thread Tools Rate Thread

How to bypass MkDir when that Dir exists already

 
 
Jan Nademlejnsky
Guest
Posts: n/a
 
      5th May 2010
I have macro which creates Subdirectories. I need to bypass MkDir command if
that folder already exists. How do you do that?

Thanks for your help.

Jan

 
Reply With Quote
 
 
 
 
ozgrid.com
Guest
Posts: n/a
 
      5th May 2010
If Dir("C:\My Doucuments") <> vbNullString Then

End If


--
Regards
Dave Hawley
www.ozgrid.com
"Jan Nademlejnsky" <(E-Mail Removed)> wrote in message
news:81FF2283-7AE0-49B7-8B98-(E-Mail Removed)...
>I have macro which creates Subdirectories. I need to bypass MkDir command
>if that folder already exists. How do you do that?
>
> Thanks for your help.
>
> Jan


 
Reply With Quote
 
Jan Nademlejnsky
Guest
Posts: n/a
 
      5th May 2010
I found it:

Sub DirectoryExists()
FPath = Range("B2")
If Dir(FPath) = "" Then '.....If
Dir("C:\Users\Owner\Documents\ExcelF\") = "" Then
MsgBox "It does not exists"
Else
MsgBox "It is already there"
End If
End Sub


"Jan Nademlejnsky" <(E-Mail Removed)> wrote in message
news:81FF2283-7AE0-49B7-8B98-(E-Mail Removed)...
> I have macro which creates Subdirectories. I need to bypass MkDir command
> if that folder already exists. How do you do that?
>
> Thanks for your help.
>
> Jan


 
Reply With Quote
 
Helmut Meukel
Guest
Posts: n/a
 
      5th May 2010
"Jan Nademlejnsky" <(E-Mail Removed)> schrieb im Newsbeitrag
news:81FF2283-7AE0-49B7-8B98-(E-Mail Removed)...
>I have macro which creates Subdirectories. I need to bypass MkDir command if
>that folder already exists. How do you do that?
>
> Thanks for your help.
>
> Jan



As others already sugested, check if the Dir exists.

Or try to create the Dir and simply ignore the error:

On Error Resume Next 'instruct VBA to ignore any error
MkDir "MyNewSubdir"
On Error GoTo 0 'no error handling
or
On Error GoTo MyErrorHandler 'reenable your previous
'error handling

Helmut.

 
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
Mkdir Greg Microsoft Access VBA Modules 2 17th Apr 2008 05:46 AM
mkdir Peter Microsoft Excel Programming 2 12th May 2007 12:48 PM
mkdir help Philip Saunders Microsoft Windows 2000 CMD Promt 3 18th Dec 2006 07:41 PM
mkdir help (1 more ?) ryan Microsoft Windows 2000 CMD Promt 2 3rd Jun 2004 06:37 PM
mkdir help ryan Microsoft Windows 2000 CMD Promt 2 3rd Jun 2004 02:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.