Option Explicit Sub abc() Dim pth, filename(), i, wb, sum pth = "c:\abc\12月工资" '指定目录,自己修改 If Dir(pth, vbDirectory) = vbNullString Then MsgBox pth: Exit Sub If Not getfilename(filename, pth, ".xlsx") Then MsgBox "!": Exit Sub Application.ScreenUpdating = False For i = 1 To UBound(filename) Set wb = Workbooks.Open(filename(i)) With wb With .ActiveSheet '当前工作表,可以指定 sum = sum + .[G100].Value End With .Close False End With Next [a1] = sum '写入当前工作表[a1]单元格 Application.ScreenUpdating = True End Sub Function getfilename(filename, pth, mark) As Boolean Dim f, n If right(pth, 1) <> "\" Then pth = pth & "\" f = Dir(pth & "*.*") Do While Len(f) > 0 If LCase(right(f, Len(mark))) = LCase(mark) Then If left(f, 1) <> "~" Then n = n + 1 ReDim Preserve filename(1 To n) filename(n) = pth & f End If End If f = Dir Loop If n > 0 Then getfilename = True End Function