|
-
Oct 1st, 2009, 03:20 PM
#1
Thread Starter
Hyperactive Member
Problem with file search wild card
I am searching a directory for a filename using a wild card (*) in the file name. The problem is that the filesearch is picking up 2 files instead of one. for example, let's say there are 2 files in the folder named xFile.xls and File.xls. If I search for "File*.xls" it returns BOTH files when it should only be returning the File.xls. Below is an example of the code. Any ideas why the wildcard isn't working like it should?
Code:
Dim FsSearch As Office.FileSearch
Set FsSearch = Application.FileSearch
TempName = "File"
With FsSearch
.NewSearch
.LookIn = ThisWorkbook.Path + "\"
.FileName = TempName & "*.xls"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
.LastModified = msoLastModifiedAnyTime
.Execute 'Count of how many records are found
For Each vaFile In .FoundFiles
Workbooks.Open vaFile, False, False
Next vaFile
End With
-
Oct 1st, 2009, 03:54 PM
#2
Re: Problem with file search wild card
Would this help?
vb Code:
Sub ListAllFiles() Dim sNextFile As String, MyPath As String, MyWildCard As String '~~> Path MyPath = "C:\temp\" '~~> File Name MyWildCard = "File" '~~> Developing the String sNextFile = Dir$(MyPath & MyWildCard & "*.xls") '~~> Search files While sNextFile <> "" '~~> Display all names of file matching criteria MsgBox sNextFile sNextFile = Dir$ Wend End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 1st, 2009, 03:59 PM
#3
Thread Starter
Hyperactive Member
Re: Problem with file search wild card
I will have to try it and get back to you... a lot of strange things have been happening lately with my macros and it doesn't make sense. This code ran fine the other day but today it is a problem. I also had an Excel macro that had a masked edit control on it... it worked fine for the past few months, then one day when we opened the file the masked edit control had a big red "X" through it and it wouldn't work. I had to replace it with a text box. I'm just wondering if these problems are related to a bigger issue going on...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|