LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default If Folder Does Exit Create

I am searching for easy VBA script to create a folder (C:\LBA\Temp)
if does not exist.


Here is a routine I once posted in the compiled VB newsgroups, but it will
work in Excel's VBA...

Sub MakeDirectories(ByVal PathIn As String)
Dim X As Long
If Right$(PathIn, 1) < "\" Then PathIn = PathIn & "\"
X = InStr(1, PathIn, "\")
Do While X < 0
If Dir$(Left$(PathIn, X), vbDirectory) = "" Then
MkDir Left$(PathIn, X)
End If
X = InStr(X & 1, PathIn, "\")
Loop
End Sub

If any part of the path already exists, it will add the part that doesn't
exist to the part that already exists. You would use it from your own code
like this...

MakeDirectories "c:\LBA\Temp"

You can chain more than the two subdirectories shown in your example
request. For example...

MakeDirectories "c:\1stDir\2ndDir\3rdDir\4thDir"

Rick

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a macro button to exit a program PACEBIT0708 Excel Worksheet Functions 1 April 23rd 08 04:43 PM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
How do i create a command button or macro to exit Microsoft Excel raj Excel Worksheet Functions 1 April 30th 05 02:17 PM
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM
Create Folder / Copy Folder / Replace Murray Outtrim[_2_] Excel Programming 0 February 24th 04 06:40 PM


All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"