![]() |
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 |
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 |
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 |
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 |
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 |
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! |
All times are GMT +1. The time now is 07:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com