![]() |
File Search code
Hi,
Try to add file extention too Abdul Salam -----Original Message----- Hi I am using the following code to open an excel file, but it is opening not the esact file Run.xls but another one ppp-Run.xls. What Change should I do? Thanks With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks End With . |
File Search code
I already done it but the result is the same
"Abdul Salam" wrote in message ... Hi, Try to add file extention too Abdul Salam -----Original Message----- Hi I am using the following code to open an excel file, but it is opening not the esact file Run.xls but another one ppp-Run.xls. What Change should I do? Thanks With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks End With . |
File Search code
With Application.FileSearch
.NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" ' .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count if lcase(Right(.FoundFiles(i),7))="\run.xls" then workbooks.open .foundfiles(i) exit for Next i Else MsgBox "file not found." End If End With MatchTextExactly only pertains to searching for a word in a document - does not pertain to the file name. Regards, Tom Ogilvy "Pedro" wrote in message ... I already done it but the result is the same "Abdul Salam" wrote in message ... Hi, Try to add file extention too Abdul Salam -----Original Message----- Hi I am using the following code to open an excel file, but it is opening not the esact file Run.xls but another one ppp-Run.xls. What Change should I do? Thanks With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks End With . |
File Search code
Note that there was an omitted End If in the original - corrected here and
generalized. Sub tester1() Dim sName As String Dim i As Long sName = "run.xls" With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .Filename = sName ' .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count If LCase(Right(.FoundFiles(i), _ Len(sName) + 1)) = "\" _ & LCase(sName) Then Workbooks.Open .FoundFiles(i) Exit For End If Next i Else MsgBox "file not found." End If End With End Sub -- Regards, Tom Ogilvy "Pedro" wrote in message ... Hi Tom Thanks for the explanation. What if insteat of a particular filename I want to search for a filename which is a variable that changes. For example StrFile = Indices and then it will change to StrFile=8876 and so on Thanks Pedro "Tom Ogilvy" wrote in message ... With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" ' .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then For i = 1 To .FoundFiles.Count if lcase(Right(.FoundFiles(i),7))="\run.xls" then workbooks.open .foundfiles(i) exit for Next i Else MsgBox "file not found." End If End With MatchTextExactly only pertains to searching for a word in a document - does not pertain to the file name. Regards, Tom Ogilvy "Pedro" wrote in message ... I already done it but the result is the same "Abdul Salam" wrote in message ... Hi, Try to add file extention too Abdul Salam -----Original Message----- Hi I am using the following code to open an excel file, but it is opening not the esact file Run.xls but another one ppp-Run.xls. What Change should I do? Thanks With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks End With . |
All times are GMT +1. The time now is 04:56 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com