Windows Message when Directory Already Exist

M

Maperalia

I have a macro that creates a directory (see below). However, I would like to
have a statement to tell me the following:
1.- Find if directory already exist.
2.- Have a window message to give me the option “YES†or “NO†to rewrite it.
3.- If I click “YES†I will rewrite it.
4.- If I click “NO†I will came back to retype the information.

Thanks in advance.
Maperalia.

'$$$$ START CREATE NEW DIRECTORY $$$$$$$$$$$$$$$$$$$$$$$$$$
NewDir = Format(Sheets("Test").Range("D5").Value)
MkDir "C:\Mario\Radius and Flat Bend\ColorLINE\Radial\ColorLine Template\" &
_ Format(Sheets("Test").Range("D5").Value)
'$$$$ END CREATE NEW DIRECTORY $$$$$$$$$$$$$$$$$$$$$$$$$$
 
C

Chip Pearson

I'm not sure what you mean in steps 3 and 4, but you can try something
like

Sub AAA()
Dim DirName As String
Dim Res As VbMsgBoxResult
DirName = "C:\Test\Test2"
If Dir(DirName, vbDirectory) = vbNullString Then
' directory does not exist
Res = MsgBox("Rewrite?", vbYesNo)
If Res = vbYes Then
' user clicked Yes
Else
' user clicked No
End If
Else
' directory exists
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
M

Maperalia

Chip;
Thanks for your quick response.
I placed your code before and after my statement and it is not working. I
believe that I am putting my statement in the wrong location. Base in the
statement I gave you (see below). Could you please tell me where I should
place your code to make it work.

Kind regards.
Maperalia.



'$$$$ START CREATE NEW DIRECTORY $$$$$$$$$$$$$$$$$$$$$$$$$$
Dim DirName As String
Dim Res As VbMsgBoxResult
DirName = "C:\Test\Test2"
If Dir(DirName, vbDirectory) = vbNullString Then
' directory does not exist
Res = MsgBox("Rewrite?", vbYesNo)
If Res = vbYes Then
' user clicked Yes
Else
' user clicked No
End If
Else
' directory exists
End If

NewDir = Format(Sheets("Test").Range("D5").Value)
MkDir "C:\Test\Test2

'$$$$ END CREATE NEW DIRECTORY $$$$$$$$$$$$$$$$$$$$$$$$$$
 

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

Top