|
|
|
Author |
Message |
rfd233
|
Posted: Wed Dec 05 15:48:57 PST 2007 |
Top |
Excel >> Create Folder with VBA
Can anybody advise me how to determine whether a folder is exist and create
that folder if it is not available.
Thank you so much!!
Excel397
|
|
|
|
|
Dave
|
Posted: Wed Dec 05 15:48:57 PST 2007 |
Top |
Excel >> Create Folder with VBA
If it's just a single level, you could just ignore any error when you try to
create the folder:
On error resume next
MkDir "C:\myfolder"
on error goto 0
>
> Can anybody advise me how to determine whether a folder is exist and create
> that folder if it is not available.
>
> Thank you so much!!
--
Dave Peterson
|
|
|
|
|
Jim
|
Posted: Wed Dec 05 15:51:02 PST 2007 |
Top |
Excel >> Create Folder with VBA
Sub CornFlakes()
Dim FSOobj As Object
Set FSOobj = CreateObject("Scripting.FilesystemObject")
If FSOobj.FolderExists("C:\DsoFile\new folder") = False Then
FSOobj.CreateFolder "C:\DsoFile\new folder"
Else
MsgBox "Folder Exists"
End If
Set FSOobj = Nothing
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
"Tommy"
Can anybody advise me how to determine whether a folder is exist and create
that folder if it is not available.
Thank you so much!!
|
|
|
|
|
Bob
|
Posted: Thu Dec 06 01:12:40 PST 2007 |
Top |
Excel >> Create Folder with VBA
Here is a generic routine to create top-down
Function CreateDirs(ByVal Path As String)
Dim mpDirs As Variant
Dim mpPart As String
Dim i As Long
mpDirs = Split(Path, Application.PathSeparator)
mpPart = mpDirs(LBound(mpDirs))
For i = LBound(mpDirs) + 1 To UBound(mpDirs)
mpPart = mpPart & Application.PathSeparator & mpDirs(i)
On Error Resume Next
MkDir mpPart
On Error GoTo 0
Next i
End Function
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
> If it's just a single level, you could just ignore any error when you try
> to
> create the folder:
>
> On error resume next
> MkDir "C:\myfolder"
> on error goto 0
>
>
>
>>
>> Can anybody advise me how to determine whether a folder is exist and
>> create
>> that folder if it is not available.
>>
>> Thank you so much!!
>
> --
>
> Dave Peterson
|
|
|
|
|
Dave
|
Posted: Thu Dec 06 06:38:03 PST 2007 |
Top |
Excel >> Create Folder with VBA
Here's something that Jim Rech Posted:
Option Explicit
Declare Function MakePath Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long
Sub Test()
MakeDir "c:\aaa\bbb"
End Sub
Sub MakeDir(DirPath As String)
If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\"
MakePath DirPath
End Sub
>
> Here is a generic routine to create top-down
>
> Function CreateDirs(ByVal Path As String)
> Dim mpDirs As Variant
> Dim mpPart As String
> Dim i As Long
> mpDirs = Split(Path, Application.PathSeparator)
>
> mpPart = mpDirs(LBound(mpDirs))
> For i = LBound(mpDirs) + 1 To UBound(mpDirs)
>
> mpPart = mpPart & Application.PathSeparator & mpDirs(i)
> On Error Resume Next
> MkDir mpPart
> On Error GoTo 0
> Next i
> End Function
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> > If it's just a single level, you could just ignore any error when you try
> > to
> > create the folder:
> >
> > On error resume next
> > MkDir "C:\myfolder"
> > on error goto 0
> >
> >
> >
> >>
> >> Can anybody advise me how to determine whether a folder is exist and
> >> create
> >> that folder if it is not available.
> >>
> >> Thank you so much!!
> >
> > --
> >
> > Dave Peterson
--
Dave Peterson
|
|
|
|
|
Tommy
|
Posted: Thu Dec 06 10:15:38 PST 2007 |
Top |
Excel >> Create Folder with VBA
Hi All
I got it
Thank you very much!!
Tommy
> Can anybody advise me how to determine whether a folder is exist and
> create that folder if it is not available.
>
> Thank you so much!!
>
>
|
|
|
|
|
|
|