|
楼主 |
发表于 2010-1-4 22:21
|
显示全部楼层
回复 38楼 3abc 的帖子
请检查工作表名是否规范,下面代码加了判断,请测试:
Sub Macro1()
Dim myPath$, myFile$, wb As Workbook, m&, sh As Worksheet
Set wb = ThisWorkbook
myPath = ThisWorkbook.Path & "\分表\"
myFile = Dir(myPath & "*.xls")
Application.ScreenUpdating = False
Do While myFile <> ""
m = m + 1
With GetObject(myPath & myFile)
For Each sh In .Sheets
If InStr(sh.Name, "中学数据表") > 0 Then
wb.Sheets("中学数据表").Cells(1, m + 3).Resize(77).Value = sh.Range("D1:D77").Value
wb.Sheets("中学数据表").Cells(2, m + 3) = m
ElseIf InStr(sh.Name, "小学数据表") > 0 Then
wb.Sheets("小学数据表").Cells(1, m + 3).Resize(77).Value = sh.Range("D1:D77").Value
wb.Sheets("小学数据表").Cells(2, m + 3) = m
End If
Next
.Close False
End With
myFile = Dir
Loop
Application.ScreenUpdating = True
MsgBox "ok"
End Sub |
|