'用于批量处理Excel文件
Sub OpenXLSFile()
Dim Path$, File$
Dim wb As Workbook, sht As Worksheet
Dim Path$, File$
Dim wb As Workbook, sht As Worksheet
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
Path = .SelectedItems(1)
File = Dir(Path & "\*.xls")
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Do Until LenB(File) = 0
Set wb = Workbooks.Open(Path & "\" & File)
For Each sht In wb.Worksheets
'加入需要处理的代码
Next
MsgBox wb.Name
wb.Close True
File = Dir
Loop
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End If
End With
End Sub
If .Show Then
Path = .SelectedItems(1)
File = Dir(Path & "\*.xls")
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Do Until LenB(File) = 0
Set wb = Workbooks.Open(Path & "\" & File)
For Each sht In wb.Worksheets
'加入需要处理的代码
Next
MsgBox wb.Name
wb.Close True
File = Dir
Loop
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End If
End With
End Sub