Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Dec 17, 4:40 pm, "Jim Rech" wrote:
If Dir("c:\aa\nul") = "" Then MkDir "c:\aa" Wow! That works great! |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Check directory permissions | Excel Programming | |||
Check a file in a directory | Excel Programming | |||
How to check if a folder/directory exist using VBA | Excel Programming | |||
How to check if the directory exists? | Excel Programming | |||
Check if directory empty OR no of files in directory. | Excel Programming |