Macro to Open excel file when file name is entered in cell
The user specified that the file extensions were .xlsx. That means that there's
a very good chance that the OP is using xl2007.
And filesearch was removed from xl2007.
Spiggy Topes wrote:
Application.FileSearch will do this for you. Lifted almost exactly
from the help sample:
Option Explicit
Private Sub CommandButton1_Click()
Dim fs As FileSearch
Dim i As Integer
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Wherever"
.SearchSubFolders = True
.Filename = Cells(1, 1)
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
Opening the file I leave to you, as you didn't say what kind of file
it might be. If it's another Excel workbook ,then
Workbooks.Open .FoundFiles(i)
would do the trick. Otherwise, you could use the ShellExecute API call
to launch the appropriate application for the selected file.
--
Dave Peterson
|