Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating multiple folder levels

Hello,
I would like to create a folder path that a user has given. If th
parent folder exists, there is no problem, but if it does not, the pat
must be created.

If the user specifies a folder path like C:\Folder1\Folder2\Folder3\
and either of Folder1, Folder2 and Folder3 exists they all must b
created.

I use the filesystemobject. I would like to do something like this:

sub createPath (myPath as string)

Set fs = CreateObject("Scripting.FileSystemObject")

fs.createfolder (myPath)

Select Case Err.Number
Case 0: ' OK, directory is created, do nothing
Case 58: 'OK, directory exists already
Err.Clear
Case 76 ' Path not found - parent folders must be created!

XXXXX

end select

end sub

Thank you!

Sir

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating multiple folder levels

if using excel 2000 or later, you don't need to go outside VBA to do this.

Sub Tester2()
Dim fFolder As Variant
Dim sStr As String, sStr1 As String
sStr = "C:\Folder1\Folder2\Folder3\"
If Right(sStr, 1) = "\" Then
sStr = Left(sStr, Len(sStr) - 1)
End If
vFolder = Split(sStr, "\")
On Error Resume Next
sStr1 = vFolder(LBound(vFolder))
For i = LBound(vFolder) + 1 To UBound(vFolder)
sStr1 = sStr1 & "\" & vFolder(i)
MkDir sStr1
Next
On Error GoTo 0

End Sub

--
Regards,
Tom Ogilvy


"SiriS " wrote in message
...
Hello,
I would like to create a folder path that a user has given. If the
parent folder exists, there is no problem, but if it does not, the path
must be created.

If the user specifies a folder path like C:\Folder1\Folder2\Folder3\
and either of Folder1, Folder2 and Folder3 exists they all must be
created.

I use the filesystemobject. I would like to do something like this:

sub createPath (myPath as string)

Set fs = CreateObject("Scripting.FileSystemObject")

fs.createfolder (myPath)

Select Case Err.Number
Case 0: ' OK, directory is created, do nothing
Case 58: 'OK, directory exists already
Err.Clear
Case 76 ' Path not found - parent folders must be created!

XXXXX

end select

end sub

Thank you!

Siri


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating multiple folder levels

Thanks !

Sir

--
Message posted from http://www.ExcelForum.com

Reply
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
Multiple levels of worksheet protection jvs Excel Worksheet Functions 1 November 7th 09 03:11 PM
Multiple levels of sumif? Peter Bellis Excel Worksheet Functions 3 August 21st 07 12:05 PM
If, Then formula - Multiple levels CPROULXM Excel Worksheet Functions 1 January 25th 07 07:47 PM
Multiple Subtotal levels in Excel 2003 Chris Luka Excel Worksheet Functions 2 April 12th 06 06:48 PM
How do I get Multiple subtotal levels in EXCEL? Minch Lewis Excel Discussion (Misc queries) 2 February 26th 05 06:04 PM


All times are GMT +1. The time now is 05:16 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"