Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Multiple levels of worksheet protection | Excel Worksheet Functions | |||
Multiple levels of sumif? | Excel Worksheet Functions | |||
If, Then formula - Multiple levels | Excel Worksheet Functions | |||
Multiple Subtotal levels in Excel 2003 | Excel Worksheet Functions | |||
How do I get Multiple subtotal levels in EXCEL? | Excel Discussion (Misc queries) |