Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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/

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default 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/



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
Stop Excel from locking files/directories you AREN'T working on? Your Display Name here... Excel Discussion (Misc queries) 1 November 20th 09 01:14 AM
How do I get excel files to open automatically from directories? Damian Excel Discussion (Misc queries) 2 January 3rd 06 02:51 PM
creating directories freekrill Excel Discussion (Misc queries) 1 July 25th 05 09:26 AM
Creating a list of directories mousetrap Excel Programming 1 July 24th 04 05:22 AM
Creating Directories Keith[_11_] Excel Programming 3 June 23rd 04 12:44 PM


All times are GMT +1. The time now is 02:46 PM.

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

About Us

"It's about Microsoft Excel"