VBA code to searching for a folder

F

Farhad

Hi,

I am new in VBA and i want to check for a folder and if the folder can not
be find creat it. any sugestion would be appriciated.

Thanks,
 
P

Pranav Vaidya

try the below code

'Declare File System object
Dim oFSO As Scripting.FileSystemObject
'Initialize File System object
Set oFSO = New Scripting.FileSystemObject
'Check if your desired folder exists
If oFSO.FolderExists("H:\Test") Then
Debug.Print "yes"
Else
'Create your desired folder as it does not exist
oFSO.CreateFolder "H:\Test"
End If

Before you use the above code make sure you have referred to MicroSoft
Scripting Runtime from Tools-->References

HTH,
 
J

Jim Rech

If Dir("C:\HopedForFolder\nul") = "" Then MkDir "C:\HopedForFolder"

--
Jim
| Hi,
|
| I am new in VBA and i want to check for a folder and if the folder can not
| be find creat it. any sugestion would be appriciated.
|
| Thanks,
| --
| Farhad Hodjat
 
Top