Open Searched File

P

Pedro

Hi
What code shoul I write in order for it to search a pre-
defined filename and open that searched file?
Someone already gave a tip to go to vba help. The vba
help for filesearch only explains how to search the file.
Now, how do I open the searched file?

Regards
Pedro
 
P

Pedro

Can you please be a little more specific
I am new on VBA
Thanks
Pedro
-----Original Message-----
In VBE help, see the Open method of the Workbook class.

HTH
Paul
--------------------------------------------------------- -----------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------- -----------------------------------------------------
 
T

Tom Ogilvy

Sub GatherFiles()
Dim sName As String
Dim sPath As String
Dim sArr() As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = False
.FileName = "MyExcelFile.xls"
'' .FileType = msoFileTypeAllFiles
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
For i = 1 To 1 ' .FoundFiles.Count
set wkbk = Workbooks.Open(.Foundfiles(i))
' workbook is now open
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

--
Regards,
Tom Ogilvy


Pedro said:
Can you please be a little more specific
I am new on VBA
Thanks
Pedro
 
P

Pedro

Hi Tom

What should I add to that if the searched file as links
and I want to update them automatically whenever I open
the file.

Thanks
Pedro


-----Original Message-----
Sub GatherFiles()
Dim sName As String
Dim sPath As String
Dim sArr() As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = False
.FileName = "MyExcelFile.xls"
'' .FileType = msoFileTypeAllFiles
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
For i = 1 To 1 ' .FoundFiles.Count
set wkbk = Workbooks.Open(.Foundfiles(i))
' workbook is now open
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
 
T

Tom Ogilvy

Sub GatherFiles()
Dim sName As String
Dim sPath As String
Dim sArr() As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = False
.FileName = "MyExcelFile.xls"
'' .FileType = msoFileTypeAllFiles
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
For i = 1 To 1 ' .FoundFiles.Count
set wkbk = Workbooks.Open(.Foundfiles(i), UpdateLinks:=3)
' workbook is now open
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top