有时将所有内容复制到新工作表中并删除您不希望保留的内容会更容易。无位置的Worksheet.Copy 方法 将打开一个带有单个工作表的新的空白工作簿;那是原件的副本。
Sub split_100()
Dim i As Long, lr As Long, fn As String
'Application.ScreenUpdating = false 'uncomment when it works right for you
With Worksheets("Sheet1")
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lr Step 100
.Copy
With ActiveWorkbook
With .Worksheets(1)
If i > 1 Then _
.Cells(1, 1).Resize(i - 1, 1).EntireRow.Delete
.Cells(101, 1).Resize(lr, 1).EntireRow.Delete
End With
fn = Environ("TMP") & "\Workbook" & Format(Int(i / 100) + 1, "00") 'no extension; leave that for xlTextWindows
'Application.DisplayAlerts = False 'uncomment to avoid overwrite warnings
.SaveAs Filename:=fn, FileFormat:=xlTextWindows
.Close SaveChanges:=False
End With
Next i
End With
Application.ScreenUpdating = True
End Sub
删除不需要的内容后,Workbook.SaveAs 方法将循环带到Workbook.Close。有多种TXT格式可供选择,以上使用的是xlTextWindows xlFileFormat。