Saturday, April 20, 2019

Creating Folders in Excel VBA

Creating Folders in Excel VBA

'In this Example I am creating a Folder "C:\SampleFolder"
Sub sbCreatingAFolder()

Dim FSO
Dim sFolder As String

sFolder= "C:\SampleFolder" ' You can Specify Any Path and Name To Create a Folder
Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FolderExists(sFolder) Then
FSO.CreateFolder (sFolder) 'Checking if the same Folder already exists
MsgBox "New FolderCreated Successfully", vbExclamation, "Done!"
Else
MsgBox "Specified Folder Already Exists", vbExclamation, "Folder Already Exists!"
End If

End Sub

No comments:

Post a Comment