![]() |
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 |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 02:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com