ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA - Creating Directories (https://www.excelbanter.com/excel-programming/308112-excel-vba-creating-directories.html)

th1chsn

Excel VBA - Creating Directories
 
Hello, I was hoping some of you on this forum will be able to help m
out with a VBA problem I seem to be having. I want to create
directory but before I create the directory I want to check to see i
it exists first.

If it exists then I want to skip creating the directory. If it doesn'
then I want to create the directory.

It sounds simple but I am having nothing but trouble trying to get i
to work.

TIA

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Excel VBA - Creating Directories
 
Easier is to just do this:

On Error Resume Next
mkdir "C:\MyFolders\MyFolders1"
On Error goto 0

This assumes that C:\MyFolders exists

--
Regards,
Tom Ogilvy

"th1chsn " wrote in message
...
Hello, I was hoping some of you on this forum will be able to help me
out with a VBA problem I seem to be having. I want to create a
directory but before I create the directory I want to check to see if
it exists first.

If it exists then I want to skip creating the directory. If it doesn't
then I want to create the directory.

It sounds simple but I am having nothing but trouble trying to get it
to work.

TIA.


---
Message posted from http://www.ExcelForum.com/




No Name

Excel VBA - Creating Directories
 
You could try this:

Public Sub CreateDirectory()

Dim strPath as string

strPath = "Your directory path goes here"

'Check to see if it exists with Dir function
If Dir(strPath) = "" Then
MkDir(strPath)
End if

End Sub



-----Original Message-----
Hello, I was hoping some of you on this forum will be

able to help me
out with a VBA problem I seem to be having. I want to

create a
directory but before I create the directory I want to

check to see if
it exists first.

If it exists then I want to skip creating the directory.

If it doesn't
then I want to create the directory.

It sounds simple but I am having nothing but trouble

trying to get it
to work.

TIA.


---
Message posted from http://www.ExcelForum.com/

.


Don Lloyd

Excel VBA - Creating Directories
 

Hi,

On Error Resume Next ' Handle error
MkDir "C:\Temp"
On Error GoTo 0 ' Cancel error handling

The above will create the folder if it doesn't exist and will skip due to an
error if the folder exists.
regards,
Don

"th1chsn " wrote in message
...
Hello, I was hoping some of you on this forum will be able to help me
out with a VBA problem I seem to be having. I want to create a
directory but before I create the directory I want to check to see if
it exists first.

If it exists then I want to skip creating the directory. If it doesn't
then I want to create the directory.

It sounds simple but I am having nothing but trouble trying to get it
to work.

TIA.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 05:09 PM.

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