Application.ScreenUpdating = False With Application.FileSearch .FileType = msoFileTypeExcelWorkbooks .LookIn = ThisWorkbook.Path .SearchSubFolders = True .Execute If .Execute() > 0 Then m = .FoundFiles.Count '当前目录及子目录所有工作薄总数 'MsgBox m For Each f In .FoundFiles '得出每个工作薄名称 'MsgBox Dir(f) '列出每个工作薄的名称,只显示名称,如 dzwebs.xls ,无路径 If (Dir(f) <> "Total.xls") Then'排除当前目录中的某个工作薄不进行操作 Set xlsApp = New Excel.Application Set xlsBook = Workbooks.Open(ThisWorkbook.Path & "\" & Dir(f)) Set MyWantGetsheet = xlsBook.Worksheets(1)'操作每个工作薄的第一个表
For i = 1 To 8 MyWantGetsheet.Cells(i, 6).Value = "www.dzwebs.net" '在每个工作薄中的指定单元格中输入数据 Next i xlsBook.Save xlsBook.Close xlsApp.Quit Set xlsApp = Nothing Set xlsBook = Nothing Set MyWantGetsheet = Nothing Application.ScreenUpdating = True End If Next End If End With