Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default 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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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)?


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default 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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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






  #11   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default 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






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
Create Folder and Text File in folder Todd Huttentsine Excel Programming 2 April 29th 04 03:41 PM
Create Folder Murray Outtrim[_4_] Excel Programming 1 March 2nd 04 06:12 PM
Create Folder / Copy Folder / Replace Murray Outtrim[_2_] Excel Programming 0 February 24th 04 06:40 PM
Create a folder.... Paiolas Excel Programming 0 September 17th 03 08:20 PM
Create Folder..... Paiolas Excel Programming 1 September 17th 03 06:39 PM


All times are GMT +1. The time now is 02:57 AM.

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

About Us

"It's about Microsoft Excel"