View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_5_] Bob Phillips[_5_] is offline
external usenet poster
 
Posts: 620
Default Create a folder.... (Post Duplicated?)

You got 2 answers,

--------------------------------------------------------------


An easy approach is to just attempt to create the folder.

If it exists, the attempt fails, so you ignore the error - otherwise it is
created:

On Error Resume Next
MkDir ThisWorkbook.Path & "\" & "Temp"
On Error goto 0


--
Regards,
Tom Ogilvy


--------------------------------------------------------------


Try this Paiolas

Sub MakeDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\Data"
If Not fs.FolderExists(Dirname) Then
fs.CreateFolder Dirname
' your code
Else
' your code
End If
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl

--------------------------------------------------------------


--

HTH

Bob Phillips

"SpeeD72" wrote in message
...
Hi

I want to create a folder in a specific place, but the
macro should only create it if the folder doesnīt exists.

Iīm using the folowing code, but it doesnīt work. Can
anybody help me?

If Object.FolderExists(ThisWorkbook.Path & "\" & "Temp")
= False Then
MkDir ThisWorkbook.Path & "\" & "Temp"
End If

thanks!

P.S: My colegue tried to post several times this question
(it just doesnīt appear!!) itīs possible that it might be
duplicated now or in the future. sorry about that!