Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check for directory then create

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Check for directory then create

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 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 533
Default Check for directory then create

If Dir("c:\aa\nul") = "" Then MkDir "c:\aa"

--
Jim
"Rex Mundi" wrote in message
...
|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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check for directory then create

On Dec 17, 4:40 pm, "Jim Rech" wrote:
If Dir("c:\aa\nul") = "" Then MkDir "c:\aa"




Wow!

That works great!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Check for directory then create

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Check for directory then create

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" wrote in message
...
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
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
Check directory permissions Dave T[_2_] Excel Programming 4 March 27th 07 03:56 PM
Check a file in a directory Rich Cooper Excel Programming 2 May 18th 04 08:56 PM
How to check if a folder/directory exist using VBA wellie Excel Programming 1 March 1st 04 02:24 AM
How to check if the directory exists? ira Excel Programming 2 January 19th 04 01:22 PM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM


All times are GMT +1. The time now is 05:34 AM.

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

About Us

"It's about Microsoft Excel"