LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
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



 
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
Test if file exists Daniel Bonallack Excel Discussion (Misc queries) 2 May 4th 09 04:19 PM
How to check if a file exists in an ftp folder LL Cool A Excel Discussion (Misc queries) 3 May 16th 06 09:22 PM
Checking to see if Folder exists Dan[_25_] Excel Programming 2 September 24th 03 02:42 AM
Test to see if a worksheet exists thanks, Chip CT[_2_] Excel Programming 0 August 22nd 03 03:17 AM
easy way to test if a Named Range exists Andrew Bauer Excel Programming 4 July 10th 03 07:32 PM


All times are GMT +1. The time now is 01:31 PM.

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

About Us

"It's about Microsoft Excel"