Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
file search or search files | Excel Discussion (Misc queries) | |||
VBA code for search button | Excel Worksheet Functions | |||
Is there a code that anables you tto search for a worksheet | Excel Discussion (Misc queries) | |||
VBA-code for search,copy and paste | Excel Discussion (Misc queries) | |||
Post Code search | New Users to Excel |