?
Solved

Excel VBA: directory exist command

Posted on 2003-12-11
2
Medium Priority
?
1,105 Views
Last Modified: 2007-12-19
what is the command for if a directory exists?

mydir = "C:\test"

if mydir exist then return true

0
Comment
Question by:yws812
  • 2
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 200 total points
ID: 9920828
Hi yws812,
Try this function, which returns True if the directory exists, false if not:

Function FolderExists(fname) As Boolean
'   Returns TRUE if the folder exists
Dim x As String, ffname As String
ffname = fname
If Right(fname, 1) <> "\" Then ffname = fname & "\"
x = Dir(ffname)
If x <> "" Then FolderExists = True _
    Else FolderExists = False
End Function

Cheers!

Brad
0
 
LVL 81

Expert Comment

by:byundt
ID: 9921093
yws812,
Thanks for the grade!
Brad
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

New style of hardware planning for Microsoft Exchange server.
MS Outlook undoubtedly is the most widely used email client.Its user-friendliness, cost effectiveness, and availability with Microsoft Office Suite make it the most popular email application.  Its compatibility with Microsoft applications like Exch…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

839 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