Solved

Create a Folder at specified drive location using VBA through Execl

Posted on 2011-02-22
3
366 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:srikanthv2322
3 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34951889
MkDir "C:\QTP\"
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34951931
Try the following
dim fso as object

set fso = createobject("scripting.filesystemobject")
if not fso.folderexists("C:\QTP\") then
    fso.createfolder("C:\QTP\")
end if

Open in new window

0
 
LVL 10

Expert Comment

by:shahzadbux
ID: 34951937

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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now