MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 22nd, 2002, 12:05 PM   #1
Beginner Bob
New Member
 
Join Date: Feb 2002
Location: San Diego
Posts: 14
Default

I am trying to search for a file using Application.FileSearch, and it keeps coming up with 3 files:

1. Actual file
2. Shortcut through WindowsApp...Office Recent
3. Shortcut through Windows Recent

How can I eliminate the shortcuts from the find procedure. I list the end of the file as ".xls" and I have tried .Filetype as "msoFileTypeExcelWorkbooks" and "XlExcelLinks", and it always comes up with same file in the same directory 3 times, as 3 files.
Beginner Bob is offline   Reply With Quote
Old Feb 24th, 2002, 02:01 PM   #2
]-[ /-\ \/\/ /-\ | | /-\
New Member
 
Join Date: Feb 2002
Location: ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
Posts: 48
Default

Bob,

Try adding to (With Application.Filesearch) specs
.Filename = "*.xls"

This will tell it to search for all files with app extension ".xls". You can replace any extension accordingly to search for appropriate files (e.g. "*.txt" will find all text docs.)

Also, make sure you specify the directory to search (.LookIn = "path here"), and also if you want appsearch to look in subdirectories or not (.SearchSubFolders = True/False). Be sure to include these two options with the (With Application.Filesearch) spec.

Hope this helps.

Aloha!

p.s. you can make the search more specific by adding more characters to the wildcard--e.g. "a*.xls" should return all Excel files that begin with the letter "a", etc...
]-[ /-\ \/\/ /-\ | | /-\ is offline   Reply With Quote
Old Feb 25th, 2002, 10:26 AM   #3
Beginner Bob
New Member
 
Join Date: Feb 2002
Location: San Diego
Posts: 14
Default

Thanks for the response Aloha, but I've tried all of that already. Without pasting my entire section of code, I've entered the following information:

With Application.Filesearch
.NewSearch
.LookIn = "C:"
.SearchSubFolders = True
.Filename = TT 'value of a certain cell called earlier in code
.MatchTextExactly = True
'I've tried .FileType = msoFileTypeExcelWorkbooks
'I've tried .FileType = XlExcelLinks
'the rest of the code

Both methods of naming the .Filetype still returned 3 results, 2 of them being shortcuts under the "Recent" folders. I'm not sure if this can even be done, but I was hoping there could be a way to eliminate the code from recognizing the shortcuts as the actual file. Thanks again.
Beginner Bob is offline   Reply With Quote
Old Feb 25th, 2002, 01:05 PM   #4
]-[ /-\ \/\/ /-\ | | /-\
New Member
 
Join Date: Feb 2002
Location: ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
Posts: 48
Default

Bob,

What is the value of 'TT'?

Aloha!
]-[ /-\ \/\/ /-\ | | /-\ is offline   Reply With Quote
Old Feb 25th, 2002, 03:09 PM   #5
Beginner Bob
New Member
 
Join Date: Feb 2002
Location: San Diego
Posts: 14
Default

Aloha, TT is the name of a payroll file called by a date entered in cell A4. All payroll files are a week apart, and are named "MM-DD-YYYY PAYROLL.xls", ie: The latest weeks are called "02-12-2002 PAYROLL.xls" and "02-19-2002 PAYROLL.xls". I have all of this set up in my code, and it finds each file with no problem, but it finds the shortcuts under the 2 "Recent" folders as well. The reason I want to search the entire C drive including subfolders instead of the specific folder which I store it in is in case the directory changes, or the file is moved, etc. The filename will definitely stay the same though. Both "Recent" folders have the root directory as "C:Windows", so I don't know if a directory can be blocked from the search. Any ideas? Thanks.
Beginner Bob is offline   Reply With Quote
Old Feb 25th, 2002, 03:56 PM   #6
]-[ /-\ \/\/ /-\ | | /-\
New Member
 
Join Date: Feb 2002
Location: ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
Posts: 48
Default

Bob,

instead of using the variable 'TT', try using:
.Filename = "*PAYROLL.XLS"

OR, (assuming Dim TT as String) use:
.Filename = TT & ".xls"

The first method narrows search down to all files ending with the word "PAYROLL" (which would seem to work in your case), but will not have as much control and flexibility as the second method. I have a feeling that your cell reference is the problem...it's PROBABLY only returning a string without the extension (.xls), hence the appsearch is returning all files with the string, and not discriminating the file extension (I don't know, but I have a suspicion it's that). The second method concatenates the extension .xls to your string and will be more specific as far as your returned results. (If you want to be sure if this is the case, add a line:
MsgBox "This is the value of TT: " & TT
anywhere after the line where you set the value of TT [Set TT = "(YourValue)"]. If it returns a string without an extension, then you have found your problem. Let me know if this works or not.

Aloha!

p.s. Aloha is just a salutation--not my nick. Those funny lookin lines by 'Username' is probably a lot harder to type though, so maybe it's better to just use that! ;{
]-[ /-\ \/\/ /-\ | | /-\ is offline   Reply With Quote
Old Feb 25th, 2002, 07:01 PM   #7
Beginner Bob
New Member
 
Join Date: Feb 2002
Location: San Diego
Posts: 14
Default

Yeah, Aloha is a little easier! Anyway, thanks for sticking with me on this. I have also tried everything you mentioned. I should have done this a while ago, but here's everything up to the open file line:

Private Sub CommandButton1_Click()
Dim OT As Worksheet, CC As Range, BB As Range
Dim TT As String, VN As String, ACT As Workbook, WBB As Workbook
'Dim other stuff here
Set ACT = ThisWorkbook
Set OT = ACT.Sheets("OVERTIME")
Set BB = OT.Range("A4")
Set CC = OT.Range("A7")
If BB.Value = "" Then
'a bunch of error checking here
Else
MT = Month(BB)
If MT < 10 Then MT = "0" & MT
DY = Day(BB)
If DY < 10 Then DY = "0" & DY
YR = Year(BB)
VN = "PAYROLL.xls"
TT = MT & "-" & DY & "-" & YR & " " & VN
With Application.FileSearch
.NewSearch
.LookIn = "C:"
.SearchSubFolders = True
.Filename = TT
.MatchTextExactly = True
.FileType = msoFileTypeExcelWorkbooks

If .Execute() > 0 Then
'rest of code here

it's definitely sloppy, but I will clean it up later. In any case, I can't use "*PAYROLL.xls" because there will be 52 files for each year (weekly payroll). I have tried the message box approach, and it names the file "C:....
Beginner Bob is offline   Reply With Quote
Old Feb 26th, 2002, 03:32 AM   #8
]-[ /-\ \/\/ /-\ | | /-\
New Member
 
Join Date: Feb 2002
Location: ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
Posts: 48
Default

Bob,

I utilize filesearch in one of my procedures, but I reference a specific folder on the network. I'm glad I did it like that from the get-go, because I wasn't aware that the filesearch would do this (list multiple files). I must say that I don't possess the knowledge or the patience to try to figure out a solution (as my approach would be to take the simple route): save all your files in a specific folder ("C:My Documents" for example) and reference that folder in your routine instead of referencing the entire C: drive and searching subfolders. Sorry!

Aloha!

p.s. I was thinking of adding "workaround code" to delete multiple instances of showing up, but afterwards, I thought the simplest approach would be the best--not to mention less work and frustration! :}
Anyways, maybe someone more knowledgable than myself will be able to assist you better. Good luck!
]-[ /-\ \/\/ /-\ | | /-\ is offline   Reply With Quote
Old Feb 26th, 2002, 10:47 AM   #9
Beginner Bob
New Member
 
Join Date: Feb 2002
Location: San Diego
Posts: 14
Default

Well thanks for all the effort, I appreciate it. I'm sure I'll figure something out.
Beginner Bob is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes