ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create a folder.... (Post Duplicated?) (https://www.excelbanter.com/excel-programming/277352-re-create-folder-post-duplicated.html)

Bob Phillips[_5_]

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!




All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com