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

文件路径固定保存在B1及B2,打开B1或B2的文件夹,搜索命名为C5的文件,并且按最新保存的日期打开文件,这个VBA要怎么写,请大神指教~~TKS!!

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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-11
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追问

不太懂,能解释下么,TKS!!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网