Link to home
Start Free TrialLog in
Avatar of srikanthv2322
srikanthv2322

asked on

Create a Folder at specified drive location using VBA through Execl

I want to create a empty folder in a specified drive location using VBA though Excel at click of Command Button

EX:
I want to create a folder name 'QTP' in Drive C
C:\QTP\

Please let me know the code for the above at a click of Command Button
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

MkDir "C:\QTP\"
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Sub CreateFolder()
Dim fso
Dim fol As String
fol = "c:\QTP" ' change to match the folder path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
    fso.CreateFolder (fol)
Else
    MsgBox fol & " already exists!", vbExclamation, "Folder Exists"
End If
End Sub

Open in new window