将查询的数据导出到Excel中,自动显示EXCEL
我将查询的数据导出到Excel中,根据记录集的条数导入到相应的单元格中,为什么第一段代码当 h < 25 时Excel能自动显示,而第二段代码只有当打开任意一Excel表才能显示
h = Adodc1.Recordset.RecordCount
k = Adodc1.Recordset.Fields.Count
If h < 25 Then
For i = 1 To h
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If
If h > 25 And h <= 50 Then
For i = 1 To 25
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
For i = 1 To h
For j = 3 To k - 18
mysheet.Cells(i + 8, j + 4) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If
[解决办法]
http://download.csdn.net/detail/veron_04/2341786