Solved

Create a Folder at specified drive location using VBA through Execl

Posted on 2011-02-22
3
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

728 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