PC Review


Reply
Thread Tools Rate Thread

Check for directory then create

 
 
Rex Mundi
Guest
Posts: n/a
 
      17th Dec 2007
I have figured out how to have Excel create a directory and save a CSV
of the current workbook.

Now the macro hangs if the directory already exists. How do I check
for the directory and create only if needed.

TIA
 
Reply With Quote
 
 
 
 
Dan R.
Guest
Posts: n/a
 
      17th Dec 2007
Try this function:

Function DirExists(PathName As String) As Boolean
Dim temp As Integer
On Error Resume Next
temp = GetAttr(PathName)
If Err.Number = 0 Then
DirExists = True
Else
DirExists = False
End If
On Error GoTo 0
End Function

--
Dan

On Dec 17, 3:07 pm, Rex Mundi <jimb...@gmail.com> wrote:
> I have figured out how to have Excel create a directory and save a CSV
> of the current workbook.
>
> Now the macro hangs if the directory already exists. How do I check
> for the directory and create only if needed.
>
> TIA

 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      17th Dec 2007
If Dir("c:\aa\nul") = "" Then MkDir "c:\aa"

--
Jim
"Rex Mundi" <(E-Mail Removed)> wrote in message
news:9e1776aa-bea1-439e-ab3a-(E-Mail Removed)...
|I have figured out how to have Excel create a directory and save a CSV
| of the current workbook.
|
| Now the macro hangs if the directory already exists. How do I check
| for the directory and create only if needed.
|
| TIA


 
Reply With Quote
 
sebastienm
Guest
Posts: n/a
 
      17th Dec 2007
Hi,
- Add a reference to the Microsoft Scripting Runtime library (menu Tools >
Reference).
- use someth8ing like:

Sub test()
Dim fso As Scripting.FileSystemObject
Dim path As String

path = "c:\test"
Set fso = New Scripting.FileSystemObject

If Not fso.FolderExists(path) Then 'does NOT exist, then create
''' create directory here
End If

''' now your FIleSave code
End Sub

--
Regards,
Sébastien
<http://www.ondemandanalysis.com>


"Rex Mundi" wrote:

> I have figured out how to have Excel create a directory and save a CSV
> of the current workbook.
>
> Now the macro hangs if the directory already exists. How do I check
> for the directory and create only if needed.
>
> TIA
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      17th Dec 2007
Just create it, don't bother checking

On Error Resume Next
MkDir "C:\test\subdir"
On Error Goto 0

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rex Mundi" <(E-Mail Removed)> wrote in message
news:9e1776aa-bea1-439e-ab3a-(E-Mail Removed)...
>I have figured out how to have Excel create a directory and save a CSV
> of the current workbook.
>
> Now the macro hangs if the directory already exists. How do I check
> for the directory and create only if needed.
>
> TIA



 
Reply With Quote
 
Rex Mundi
Guest
Posts: n/a
 
      18th Dec 2007
On Dec 17, 4:40 pm, "Jim Rech" <jrr...@live.com> wrote:
> If Dir("c:\aa\nul") = "" Then MkDir "c:\aa"
>




Wow!

That works great!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to check if a directory exists / and create it if it doesn't CCLeasing Microsoft C# .NET 2 10th Nov 2006 02:40 PM
Web Setup project - create virtual directory & point to another location in directory structure kplkumar@gmail.com Microsoft C# .NET 0 12th Apr 2006 06:26 PM
Unable to create directory under . Please check write access... =?Utf-8?B?TGVzc2llbg==?= Windows XP Accessibility 1 8th Aug 2004 09:25 AM
vcdeploy : error VCD0035: Failed to create the file system directory for the virtual directory. Access is denied. Dominic Microsoft VC .NET 0 17th Jun 2004 01:27 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Microsoft Excel Programming 2 4th Dec 2003 10:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:49 PM.