excel运用VBA打开文件夹并搜索打开文件:
文件路径固定保存在B1及B2,打开B1或B2的文件夹,搜索命名为C5的文件,并且按最新保存的日期打开文件,这个VBA要怎么写,请大神指教~~TKS!!...
文件路径固定保存在B1及B2,打开B1或B2的文件夹,搜索命名为C5的文件,并且按最新保存的日期打开文件,这个VBA要怎么写,请大神指教~~TKS!!
展开
2个回答
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
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!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询