EXCEL宏命令修改。怎样把单一工作簿内的宏命令修改到可以一次性应用到某个文件夹内?
发布网友
发布时间:2022-06-28 09:24
我来回答
共1个回答
热心网友
时间:2023-10-09 03:37
运行时,会有提示窗,选定好一个或多个工作薄后,自动执行,最后提示 “完成”
Sub 筛选_选定的工作簿()
Dim iBk As Workbook, sh As Worksheet, i%, j%, iFiles
iFiles = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , "请选择要汇总的工作簿", , True)
If IsArray(iFiles) = 0 Then MsgBox "没有选择文件!": Exit Sub
For i = LBound(iFiles) To UBound(iFiles)
Set iBk = Workbooks.Open(iFiles(i))
With iBk.Worksheets(1)
.Cells.ColumnWidth = 2
With .Range("V3")
.Select
.AutoFilter
.AutoFilter Field:=21, Criteria1:="<>9999", Operator:=xlAnd
.AutoFilter Field:=2, Criteria1:="<> ", Operator:=xlAnd
.AutoFilter Field:=8, Criteria1:="<>9999", Operator:=xlAnd
.AutoFilter Field:=3, Criteria1:="<>9999", Operator:=xlAnd
.AutoFilter Field:=11, Criteria1:="<> ", Operator:=xlAnd
End With
End With
Application.DisplayAlerts = False
iBk.Close True
Application.DisplayAlerts = False
Next i
Set iBk = Nothing
MsgBox "完成!"
End Sub