首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

百思不得其解,请指点一上,万分感谢

2012-09-19 
百思不得其解,请指点一下,万分感谢Dim i As Integer, j As Integer, h As Integer, k As Integer, m As In

百思不得其解,请指点一下,万分感谢
Dim i As Integer, j As Integer, h As Integer, k As Integer, m As Integer, n As Integer, X As Integer
  h = Adodc1.Recordset.RecordCount
  k = Adodc1.Recordset.Fields.Count  
  Dim myexcel As New Excel.Application '定义一个新的Excel对象
  Dim mybook As New Excel.Workbook '定义一个新的BOOK对象
  Dim mysheet As New Excel.Worksheet '定义一个新的SHEET对象
  Set mybook = myexcel.Workbooks.Add '添加一个新的BOOK
  Set mysheet = mybook.Worksheets(1) '设置活动工作表
  mysheet.Columns("A:F").HorizontalAlignment = xlCenter '单元格居中
  mysheet.Range(Cells(1, 1), Cells(1 + h, 10)).Borders.LineStyle = xlContinuous '单元格边框
   
  For i = 1 To h  
 For j = 1 To k  
 mysheet.Cells(i , j) = Adodc1.Recordset.Fields.Item(j).Value
  Next j
  Adodc1.Recordset.MoveNext
  Next i  
  myexcel.Visible = True
这段代码程序执行一次成功,再执行就不行了,必须关闭后在启动程序方能执行
我试了把mysheet.Range(Cells(1, 1), Cells(1 + h, 10)).Borders.LineStyle = xlContinuous '单元格边框
去掉可多次执行成功,可加上就不行,请问这是什么原因,请各位指点一下,该怎么改呢?

[解决办法]
http://download.csdn.net/detail/veron_04/2341786
[解决办法]
在最后加下面语句就可以了
Set mybook = Nothing
Set mysheet = Nothing
Set myexcel = Nothing

热点排行