Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check and Create Folder Method 1

Status
Not open for further replies.

jessedh

MIS
Apr 16, 2002
96
US
I am trying out this code, but it isn't working. Any help on this whole filesys thing would be appreciated as I am new to this and have no clue how it work or what the correct syntax is....

Thanks
Jesse

Public Function MakeDir()

Dim Dir As String
Dim FormattedDate As String
Dim strFileName As String
Dim Final As String


Dir = "F:\SHARED_4\Jesse\Weekly Files\"
FormattedDate = Format(Date - 3, "MM-DD-YY")
Final = Dir & FormattedDate

If FileSystem.FolderExists(Final) = False Then
MsgBox "File Doesn't exist"
MkDir Final
Else
MsgBox "File Exists!"
End If


End Function
 
Jesse,

You need to get access to the FileSystemObject before referencing it:

Code:
Dim fs as Object

Set fs = CreateObject("Scripting.FileSystemObject")
IF fs.FolderExists(final) = False Then
...


HTH
M. Smith
 
Try the VBA "Dir" function. You can use it to see if a file exists. It might also work to determine if a folder exists. I will try it when I have time and let u know.
 
FYI when I used Dir to test for the presence of a folder it would fail if the folder contained no files, but only work if the folder contained files. not sure if I was doing anything wrong when using Dir, but RMikeSmith's solution worked perfectly for me.
 
kchernak,

I ran the following little test procedure and it works with a folder (directory) whether or not it is empty:

Code:
Sub test()
Dim f As String
  f = Dir("F:\SomeFolder", vbDirectory)
  If f <> &quot;&quot; Then
    'Folder exists (f will contain SomeFolder)
  Else
    'Folder doesn't exist
  End If
End Sub


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top