|
求助各位大侠,为什么在将多个excel文件中的表单合并到一个excel中的表单中的代码不对,红色加粗部分,总提示:“缺少: 行号 或 标签 或 语句 或 语句结束”,怎么处理?请求大侠们帮助,感谢!
Sub Combinefiles()
Dim path As String
Dim filename As String
Dim lastcell As Range
Dim wkb As Workbook
Dim ws As Worksheet
Dim thiswb As String
Dim mydir As String
mydir = ThisWorkbook.path & "\"
'chdrive left(mydir,1)'find all the excel files
'chdir mydir
'match = dir$("")
thiswb = ThisWorkbook.Name
Application.EnableEvents = False
Application.ScreenUpdating = False
path = mydir
filename = Dir(path & "\*.xls", vbNormal)
Do Until filename = ""
If filename <> thiswb Then
Set wkb = Workbooks.Open(filename:=path & "\" & filename)
For Each ws In wkb.Worksheets
Set lastcell = ws.Cells.SpecialCells(xlCellTypeLastCell)
If lastcell.Value = ""And lastcell.Address = range("$A$1").Address
Then
Else
ws.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End If
Next ws
wkb.Close False
End If
filename = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
Set wkb = Nothing
Set lastcell = Nothing
End Sub
再次感谢!!!
|
|