VBA code to searching for a folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
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,
 
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
 
Back
Top