答:我写了段代码。如下:
Sub Demo()
Dim FilePath As String
Dim FileName As String
If IsEmpty(ActiveCell) Then Exit Sub
FilePath = "D:\工艺文件\"
FileName = Replace(ActiveCell.Value, "/", "-") & ".xls*"
Call ReDir(FilePath, FileName)
End Sub
Public Sub ReDir(ByVal CurrDir As String, ByVal FindName As String)
Dim Dirs() As String
Dim NumDirs As Long
Dim TotalFiles, SingleFile
Dim TotalFolders, SingleFolder
Dim fso As Object, f
Set fso = CreateObject("scripting.filesystemobject")
Set TotalFiles = fso.GetFolder(CurrDir).Files
Set TotalFolders = fso.GetFolder(CurrDir).SubFolders
If TotalFiles.Count <> 0 Then
For Each SingleFile In TotalFiles
If fso.GetFile(SingleFile).Name Like FindName Then
Workbooks.Open FileName:=SingleFile
End If
Next
End If
If TotalFolders.Count <> 0 Then
For Each SingleFolder In TotalFolders
ReDim Preserve Dirs(0 To NumDirs) As String
Dirs(NumDirs) = SingleFolder
NumDirs = NumDirs + 1
Next
End If
For i = 0 To NumDirs - 1
Call ReDir(Dirs(i), FindName)
Next i
End Sub
快捷键设置,见下图,点"宏"按钮,打开宏对话框,然后设置快捷键。之后,鼠标选中1个单元格就可以用快捷键执行打开文件操作了。