ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   create a folder (https://www.excelbanter.com/excel-programming/327615-create-folder.html)

Bob

create a folder
 
I have a module that saves workbooks through VB, but sometimes the file does
not exists, what can I do so that when the folder does not exists it must
create the folder for the workbook?

Thanks
Bob

Tom Ogilvy

create a folder
 
On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.

--
Regards,
Tom Ogilvy


"Bob" wrote in message
...
I have a module that saves workbooks through VB, but sometimes the file

does
not exists, what can I do so that when the folder does not exists it must
create the folder for the workbook?

Thanks
Bob




Bob Phillips[_6_]

create a folder
 
Be aware that if you have a multi-level directory structure, you will need
to make each one separately

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Tom Ogilvy" wrote in message
...
On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.

--
Regards,
Tom Ogilvy


"Bob" wrote in message
...
I have a module that saves workbooks through VB, but sometimes the file

does
not exists, what can I do so that when the folder does not exists it

must
create the folder for the workbook?

Thanks
Bob






Amedee Van Gasse[_3_]

create a folder
 
Tom Ogilvy shared this with us in microsoft.public.excel.programming:

On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.


Or use the CreateFolder method from FileSystemObject:

Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function

There is even a FolderExists method! Call this before creating your
folder.

Function ReportFolderStatus(fldr)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
msg = fldr & " exists."
Else
msg = fldr & " doesn't exist."
End If
ReportFolderStatus = msg
End Function

It's a more "modern" way of programming. On Error is rather cluncky and
created spaghetti code, FileSystemObject is really Object Oriented. But
it's not my way or the highway: please try both and use what you like
best.

(Hey, please no discussions about early/late binding. I just copied
this from some page on the MSDN DVD. Don't shoot the messenger.)

--
Amedee Van Gasse using XanaNews 1.17.3.1
If it has an "X" in the name, it must be Linux?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Only ask questions with yes/no answers if you want "yes" or "no" as the
answer.
http://homepages.tesco.net/~J.deBoyn...-with-yes-or-n
o-answers.html

Bob Phillips[_6_]

create a folder
 
Hi Amadee,

Whilst alternatives are good, this seems unnecessarily complex given Tom's
simple, elegant solution. Tom's code creates it if it does not exist,
ignores it otherwise, no need for folderexists!

You say FSO is the 'modern' way, it is just a later technology (which some
organisations might wish to suppress BTW) which AFAICS seeks to bring
together a number of disparate file oriented techniques. It is useful,
especially with lots of file handling functions, but IMO overkill for this
need.

And how do you come to the conclusion that OnError is chunky and creates
spaghetti code in the example supplied. It can do, but so can FSO and
anything else in the wrong hands.

And as for late-binding ... oops, you said don't go there :-). Seriously
though, as presented, the code could be either late or early binding, it
depends upon whether a reference to the type library is set.

Regards

Bob


"Amedee Van Gasse" wrote in message
...
Tom Ogilvy shared this with us in microsoft.public.excel.programming:

On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.


Or use the CreateFolder method from FileSystemObject:

Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function

There is even a FolderExists method! Call this before creating your
folder.

Function ReportFolderStatus(fldr)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
msg = fldr & " exists."
Else
msg = fldr & " doesn't exist."
End If
ReportFolderStatus = msg
End Function

It's a more "modern" way of programming. On Error is rather cluncky and
created spaghetti code, FileSystemObject is really Object Oriented. But
it's not my way or the highway: please try both and use what you like
best.

(Hey, please no discussions about early/late binding. I just copied
this from some page on the MSDN DVD. Don't shoot the messenger.)

--
Amedee Van Gasse using XanaNews 1.17.3.1
If it has an "X" in the name, it must be Linux?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Only ask questions with yes/no answers if you want "yes" or "no" as the
answer.
http://homepages.tesco.net/~J.deBoyn...-with-yes-or-n
o-answers.html




Bob Phillips[_6_]

create a folder
 
Ooops, sorry for mis-spelling your name

Bob


"Bob Phillips" wrote in message
...
Hi Amadee,

Whilst alternatives are good, this seems unnecessarily complex given Tom's
simple, elegant solution. Tom's code creates it if it does not exist,
ignores it otherwise, no need for folderexists!

You say FSO is the 'modern' way, it is just a later technology (which some
organisations might wish to suppress BTW) which AFAICS seeks to bring
together a number of disparate file oriented techniques. It is useful,
especially with lots of file handling functions, but IMO overkill for this
need.

And how do you come to the conclusion that OnError is chunky and creates
spaghetti code in the example supplied. It can do, but so can FSO and
anything else in the wrong hands.

And as for late-binding ... oops, you said don't go there :-). Seriously
though, as presented, the code could be either late or early binding, it
depends upon whether a reference to the type library is set.

Regards

Bob


"Amedee Van Gasse" wrote in message
...
Tom Ogilvy shared this with us in microsoft.public.excel.programming:

On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.


Or use the CreateFolder method from FileSystemObject:

Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function

There is even a FolderExists method! Call this before creating your
folder.

Function ReportFolderStatus(fldr)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
msg = fldr & " exists."
Else
msg = fldr & " doesn't exist."
End If
ReportFolderStatus = msg
End Function

It's a more "modern" way of programming. On Error is rather cluncky and
created spaghetti code, FileSystemObject is really Object Oriented. But
it's not my way or the highway: please try both and use what you like
best.

(Hey, please no discussions about early/late binding. I just copied
this from some page on the MSDN DVD. Don't shoot the messenger.)

--
Amedee Van Gasse using XanaNews 1.17.3.1
If it has an "X" in the name, it must be Linux?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Only ask questions with yes/no answers if you want "yes" or "no" as the
answer.
http://homepages.tesco.net/~J.deBoyn...-with-yes-or-n
o-answers.html






Amedee Van Gasse[_3_]

create a folder
 
Bob Phillips shared this with us in microsoft.public.excel.programming:

Ooops, sorry for mis-spelling your name

Bob


Good for you, because I was just getting ready to dig up my LART (a
piledriver and 16 feet of curare-tipped wrought-iron fence and no
lubricants!)

--
Amedee Van Gasse using XanaNews 1.17.3.1
If it has an "X" in the name, it must be Linux?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
Only ask questions with yes/no answers if you want "yes" or "no" as the
answer.
http://homepages.tesco.net/~J.deBoyn...-with-yes-or-n
o-answers.html

Bob Phillips[_6_]

create a folder
 

"Amedee Van Gasse" wrote in message
...

Good for you, because I was just getting ready to dig up my LART (a
piledriver and 16 feet of curare-tipped wrought-iron fence and no
lubricants!)


Are all Linux'ers as aggressive? And what would a LART be used for
(Currently)?



Amedee Van Gasse[_3_]

create a folder
 
Bob Phillips shared this with us in microsoft.public.excel.programming:


"Amedee Van Gasse" wrote in message
...

Good for you, because I was just getting ready to dig up my LART (a
piledriver and 16 feet of curare-tipped wrought-iron fence and no
lubricants!)


Are all Linux'ers as aggressive? And what would a LART be used for
(Currently)?


I forgot the <irony tags.
And I'm only a part-time Linux user. I'm more a CrossOver(tm) user:
best of both worlds.

--
Amedee Van Gasse using XanaNews 1.17.3.1

Bob Phillips[_6_]

create a folder
 
So did I <g.

But you still haven't told me what a LART would be used for.

Bob


"Amedee Van Gasse" wrote in message
...
Bob Phillips shared this with us in microsoft.public.excel.programming:


"Amedee Van Gasse" wrote in message
...

Good for you, because I was just getting ready to dig up my LART (a
piledriver and 16 feet of curare-tipped wrought-iron fence and no
lubricants!)


Are all Linux'ers as aggressive? And what would a LART be used for
(Currently)?


I forgot the <irony tags.
And I'm only a part-time Linux user. I'm more a CrossOver(tm) user:
best of both worlds.

--
Amedee Van Gasse using XanaNews 1.17.3.1





Bob

create a folder
 
Thanks Tom and Amedee you guys were a create help.

Regards
Bob

"Bob Phillips" wrote:

Be aware that if you have a multi-level directory structure, you will need
to make each one separately

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Tom Ogilvy" wrote in message
...
On Error Resume Next
Mkdir "c:\Myfolder"
On Error goto 0

Then you are sure it exists.

--
Regards,
Tom Ogilvy


"Bob" wrote in message
...
I have a module that saves workbooks through VB, but sometimes the file

does
not exists, what can I do so that when the folder does not exists it

must
create the folder for the workbook?

Thanks
Bob








All times are GMT +1. The time now is 06:52 AM.

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