帮你把问题代码找出来了,好象少了什么关闭语句.
打开文件没问题,每运行此代码一次后,内存占用增加 150多M
此时任何操作都很慢,双击单元格都要4秒才有反应.
运行多几次会死机.关闭文件后正常
这方面水平不高,期待高手解答.
Sub love() Dim sht As Worksheet Sheets("生成表").Range("A5:S500").Clear For Each sht In Worksheets If sht.Name <> "生成表" Then Set jmyb = CreateObject("ADODB.Connection") jmyb.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName For i = 2 To [ah200].End(xlUp).Row Sql = "select * from [" & sht.Name & "$] where 合并='" & Range("ah" & i) & "'" Set lsy = jmyb.Execute(Sql) Sheets("生成表").[a65536].End(xlUp).Offset(1, 0).CopyFromRecordset lsy, , 22 Next i Set lsy = Nothing: Set jmyb = Nothing End If Next End Sub
|