excel运用VBA打开文件夹并搜索打开文件:

2025-03-13 20:33:54
推荐回答(2个)
回答1:

wb=range("B1") & "\" & range("C5") & ".xls"
workbooks.open(wb)

回答2:

Dim c As Worksheet, addr As String, cou As Integer, coun As Integer
Dim path As String, str As String, actsh As Worksheet, keyword As String, i As Integer
Dim fil As String
path = InputBox("Please input the folder path of excel file need combine")
'or path="\\svr001\公用文档"
keyword = activecell.value
If InStr(1, path, ":") < 1 And InStr(1, path, "\\") < 1 Then GoTo ne
If Right(path, 1) = "\" Then path = left(path, Len(path) - 1)
If Len(Trim(keyword)) < 1 Then GoTo ne
cou = 0
Application.ScreenUpdating = False
With Application.FileSearch
.LookIn = path
.FileName = "*" & keyword & "*.xls"
If .Execute > 0 Then
coun = .FoundFiles.count
For i = 1 To coun
Workbooks.Open (.FoundFiles(i))
Next i
End If
End With
Range("A1:A2").EntireRow.Delete
Application.ScreenUpdating = True
MsgBox ("Total processed " & cou & " files!")
ne:
End Sub