Hi chico,
If you are trying to verify that a folder exists?
If I missed the question, try it again :wink2:
.....Ralph
Hi All,
Just like to know if anyone knows how to search for a folder instead of a file so that I can assign the name of the path as a string variable. Thanks in advance.
Hi chico,
If you are trying to verify that a folder exists?
If I missed the question, try it again :wink2:
.....Ralph
Last edited by Dave Hawley; May 4th, 2010 at 10:24.
Wow! This is a toughie!
Ralphs suggestion will tell if the folder exists but for that you need the path.
To actually search for a folder and then return the path is much tougher than I imagined. I have dug up code that will reurn the path of special folders no matter where they are (eg: MyDocuments) and I have looked at SearchScope property which you can apparently add items to (as in additional folders) to be incuded in a search of folders - but I havent figured out how to do itcangry:
I will keep trying while I have time and I look foward to anyone else coming up with a solution to this harder than it sounds problem.
Regards
Weasel
Kind Regards
Pesky Weasel
"I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
Eagles may soar, but Weasels don't get sucked into jet engines.
Templates and Calculators
The Way of the Weasel
Download Ivan & Colo's HTML Maker Here
101 Excel Hacks - Great New Book
Huge Savings on Excel Training
Thanks for your speedy reply. At the moment I have a piece of code that can find a file but I need to see if it can find a folder only. The reason for this is because people have a tendency to move the folder and it contents to different locations in the drive.
I am trying to write some code that can open several files from locating a specified folder. Below is a snippet of code that finds all the excel files. Can I change this to look for a folder. The foldername is the root directory.
VB:Set wbCodeBook = ThisWorkbook With Application.FileSearch .NewSearch 'Change path to suit .LookIn = FolderName .FileType = msoFileTypeExcelWorkbooks .Execute End With
Last edited by Dave Hawley; May 4th, 2010 at 10:23.
Will the folder you are looking for always contain a certain file.
ie Folder named BOB
will always have a spreadsheet named JOHN.xls inside?
Weasel
Kind Regards
Pesky Weasel
"I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
Eagles may soar, but Weasels don't get sucked into jet engines.
Templates and Calculators
The Way of the Weasel
Download Ivan & Colo's HTML Maker Here
101 Excel Hacks - Great New Book
Huge Savings on Excel Training
Yes that's correct John will always be in Bob. Basically any John, Susan or Marys that exist in Bob are to be dealt to.
Whoops sorry Weasel I might have mislead you. Bob doesn't require a certain John. The name of the files change. Thanks for your reply,
Regards,
Kiwichico
Sub tester()
Const FolderToFind As String = "C:\A\"
If Len(Dir(FolderToFind)) = 0 Then
MsgBox FolderToFind & " doesn't exits"
Else
MsgBox FolderToFind & " exits"
End If
End Sub
Ivan,
Cant get that example to return a positve result. Could you eloborate on what it is supposed to do?
Regards
Weasel
Kind Regards
Pesky Weasel
"I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
Eagles may soar, but Weasels don't get sucked into jet engines.
Templates and Calculators
The Way of the Weasel
Download Ivan & Colo's HTML Maker Here
101 Excel Hacks - Great New Book
Huge Savings on Excel Training
OK - I got working some of the time.
However, you need to know the file path in order to see if it exists.
What the OP would like to do is enter a folder name and have excel search to see if the folder exists similar to the windows Find Files & Folders utility.
Can this be accessed and controlled through Excel using API calls?
Regards
Weasel
Kind Regards
Pesky Weasel
"I have a plan so cunning, you could put a tail on it and call it a Weasel." EB
Eagles may soar, but Weasels don't get sucked into jet engines.
Templates and Calculators
The Way of the Weasel
Download Ivan & Colo's HTML Maker Here
101 Excel Hacks - Great New Book
Huge Savings on Excel Training
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks