View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] pfsardella@yahoo.com is offline
external usenet poster
 
Posts: 96
Default Test if a folder exists

Here are three different approaches gathered from previous postings.

-----------------------------------------------------------

Public Function IsDir(ByRef strPath As String) As Boolean
'' Does the directory exist?

If Not Dir(strPath, vbDirectory) = vbNullString Then IsDir = True

End Function

-----------------------------------------------------------

Sub MakeDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\Data"
If Not fs.FolderExists(Dirname) Then
fs.CreateFolder Dirname
' your code
Else
' your code
End If
End Sub

Courtesy of a posting by Ron De Bruin

-----------------------------------------------------------

An easy approach is to just attempt to create the folder.

If it exists, the attempt fails, so you ignore the error - otherwise
it is created:

On Error Resume Next
MkDir ThisWorkbook.Path & "\" & "Temp"
On Error goto 0

Tom Ogilvy

-----------------------------------------------------------

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------
On Sun, 28 Sep 2003 10:52:16 -0400, "Jeff Marshall"
wrote:

Hi,

I am making a folder using VBA called "SeptInv" in C:\Billing\Invoices\ .

However before the folder is made I don't know how to;

1. Test if the SeptInv folder has already been made and
2. Once it has been made that my VBA macro doesn't try to make it again.

Thanks in advance for any help.
Jeff