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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top