ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Testing for a directory (https://www.excelbanter.com/excel-programming/422151-testing-directory.html)

MarkS

Testing for a directory
 
Hi,
I need to test if a directory exists and if not create it. All I can think
of is to use on error and try and open it, they create a new directory if it
fails.
Any sugestions of a more elegant way

Nigel[_2_]

Testing for a directory
 
This works for me.....

Dim sFolder As String
sFolder = "C:\NewFolder"

If Dir(sFolder, vbDirectory) = "" Then MkDir sFolder


--

Regards,
Nigel




"MarkS" wrote in message
...
Hi,
I need to test if a directory exists and if not create it. All I can think
of is to use on error and try and open it, they create a new directory if
it
fails.
Any sugestions of a more elegant way



Bob Phillips[_3_]

Testing for a directory
 
Just create it with error warp

On Error Resume Next
MkDir myDir
On Error Goto 0

--
__________________________________
HTH

Bob

"MarkS" wrote in message
...
Hi,
I need to test if a directory exists and if not create it. All I can think
of is to use on error and try and open it, they create a new directory if
it
fails.
Any sugestions of a more elegant way




MarkS

Testing for a directory
 
Thanks that work just great

"Nigel" wrote:

This works for me.....

Dim sFolder As String
sFolder = "C:\NewFolder"

If Dir(sFolder, vbDirectory) = "" Then MkDir sFolder


--

Regards,
Nigel




"MarkS" wrote in message
...
Hi,
I need to test if a directory exists and if not create it. All I can think
of is to use on error and try and open it, they create a new directory if
it
fails.
Any sugestions of a more elegant way





All times are GMT +1. The time now is 11:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com