#1   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 38
Default Creating a folder

Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?, Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 638
Default Creating a folder

One way:
Sub addFolder()
Dim pth As String
pth = "I:\Mybackup\"
If Dir(pth, vbDirectory) = "" Then
MkDir pth
Else
MsgBox "exists"
End If
End Sub

Another way:
On Error Resume Next
MkDir "I:\Mybackup\"
On Error GoTo0

I personally prefer the first way.
dan wrote:
Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?, Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Creating a folder

Use Dir

Sub test()

' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?, Please.

If Dir("C:\Mybackup\") = "" Then
MkDir ("C:\temp\Mybackup\")
End If
End Sub

"dan" wrote:

Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?, Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 38
Default Creating a folder

Thank you very much, JW

"JW" wrote in message
oups.com...
One way:
Sub addFolder()
Dim pth As String
pth = "I:\Mybackup\"
If Dir(pth, vbDirectory) = "" Then
MkDir pth
Else
MsgBox "exists"
End If
End Sub

Another way:
On Error Resume Next
MkDir "I:\Mybackup\"
On Error GoTo0

I personally prefer the first way.
dan wrote:
Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?,
Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 38
Default Creating a folder

Hi Joel,
I like your simple statement.
Thank you very much.

"Joel" wrote in message
...
Use Dir

Sub test()

' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?,
Please.

If Dir("C:\Mybackup\") = "" Then
MkDir ("C:\temp\Mybackup\")
End If
End Sub

"dan" wrote:

Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?,
Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub







  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Creating a folder

Maybe you can just ignore the error if the folder already exists:

on error resume next
mkdir "I:\mybackup"
on error goto 0

dan wrote:

Sub test()
' I want to creat a folder if that folder doesn't exist in the path.
' The following statement is not supported. What is the right way?, Please.

If Not Application.exist("I:\Mybackup\") Then MkDir ("I:\Mybackup\")
End Sub


--

Dave Peterson
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
Creating a new folder that does not already exsit. Ryan Excel Discussion (Misc queries) 3 July 16th 07 10:10 PM
Creating a List of the files in a folder in excel [email protected] Excel Discussion (Misc queries) 2 November 27th 06 08:39 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
creating an XLS file from " files" data in a Folder Edwin Mashiringwani Excel Discussion (Misc queries) 2 November 19th 05 04:45 PM


All times are GMT +1. The time now is 06:58 AM.

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"